委托:就是指向一个函数的引用;通俗来说就是:将方法作为参数的来使用
被调用的方法参数个数、参数类型,必须和, 委托的方法参数个数、参数类型 ,要一致:
1 delegate void DeleShow(string msg);//定义委托方法 2 class Program 3 { 4 static void Main(string[] args) 5 { 6 DeleShow obj = new DeleShow(Test.Show);//使用委托调用方法一 7 obj += new DeleShow(Test.ShoTwo);//使用委托调用方法二 8 obj("谢谢!"); 9 Console.ReadLine(); 10 } 11 } 12 13 14 public class Test 15 { 16 17 public static void Show(string msssg) 18 { 19 Console.WriteLine("方法一:" + msssg); 20 } 21 22 public static void ShoTwo(string msssg) 23 { 24 Console.WriteLine("方法二:" + msssg); 25 } 26 27 }