利用委托实现一个打印完成事件
正常方法:
- public delegate void Print();//定义委托
- class Printer{
- public static void PrintFinished(){
- Console.WriteLine("正常方法打印完成!");
- }
- }
- public static void Main(string[] args){
- Print dele;
- dele=Printer.PrintFinished;//绑定方法
- dele();
- }
匿名方法:使用delegate(XXX,xxx,XXX xxx){...};
- public static void Main(string[] args){
- Print dele=delegate(){//绑定匿名方法
- Console.WriteLine("匿名方法的打印完成");
- };
- dele();
- }

520

被折叠的 条评论
为什么被折叠?



