半斤八两的程序员

.net默默无语的追随者.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

学习笔记:c#函数名可以直接赋值给委托

Posted on 2009-03-23 17:17  炸弹  阅读(920)  评论(1)    收藏  举报

一直不知道也可以这样,今天看书发现的,也许比较弱智。

 1         public delegate void MyDelegate(int x,int y);
 2         public static void Main(string[] args)
 3         {
 4             MyDelegate my1 = PrintPair;
 5             my1(6,4);
 6         }
 7         static void PrintPair(int x,int y)
 8         {
 9             Console.WriteLine(x.ToString()+"\n"+y.ToString());
10             Console.Read();
11         }
原来我一直都是用委托实例的厄。。

 1         public delegate void MyDelegate(int x,int y);
 2         public static void Main(string[] args)
 3         {
 4             MyDelegate my1 = new MyDelegate(PrintPair);
 5             my1(6,4);
 6         }
 7         static void PrintPair(int x,int y)
 8         {
 9             Console.WriteLine(x.ToString()+"\n"+y.ToString());
10             Console.Read();
11         }
这样更像是委托链嘛 orz

 

風之谷