C# 正则表达式,Delegates 与 Exception

正则表达式用来处理复杂的String

 1 using System;
 2 using System.Text;
 3 using System.Text.RegularExpressions;
 4 public class Tester
 5 {
 6     static void Main()
 7     {
 8         string s1 = "One,Two,Three Liberty Associates, Inc.";
 9         Regex theRegex = new Regex(" |, |,");
10         StringBuilder sBuilder = new StringBuilder(); int id = 1;
11         foreach (string subString in theRegex.Split(s1))
12         {
13             sBuilder.AppendFormat("{0}: {1}\n", id++, subString);
14         }
15         Console.WriteLine("{0}", sBuilder);
16     }
17 }

 

delegates 类似C++的函数指针

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Text.RegularExpressions;
 7 
 8 namespace ConsoleApplication8
 9 {
10     delegate int Sample(int x, int y);  //定义delegate方法
11     class Class2
12     {
13         public int method(int x, int y)
14         { return x * y; }
15     }
16     class Class1
17     {
18         static void Main(string[] args)
19         {
20             Class2 instance = new Class2();
21             Sample mySample                         // 调用delegate的构造方法
22                    = new Sample(instance.method);   // 生成mySample实体
23             int result = mySample(2, 3);
24             Console.WriteLine(result);          // 输出结果 6
25         }
26     }
27 }

Exceptions

throw exception后,throw后的代码不执行

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace ConsoleApplication8
{
    public class Test
    {
     public static void Main()
     {
        Console.WriteLine("Enter Main...");
       Test t = new Test();
       t.Func1();
       Console.WriteLine("Exit Main...");   //未执行
     }
     public void Func1()
     {
         Console.WriteLine("Enter Func1...");
         Func2();
         Console.WriteLine("Exit Func1...");  //未执行
     }
        public void Func2()
    {
        Console.WriteLine("Enter Func2...");
         throw new System.ApplicationException();   //抛出 
         Console.WriteLine("Exit Func2...");        // 未执行
     }
    }
    
}

只在主函数中 catch 异常。

转载于:https://www.cnblogs.com/yi-jie/p/4442284.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值