1 delegate void NumberCalculator(int a); 2 class Program 3 { 4 static int num1 = 100; 5 static void Main(string[] args) 6 { 7 /*1、委托的多播*/ 8 NumberCalculator delegates; 9 NumberCalculator addCalculator = new NumberCalculator(Add); 10 NumberCalculator multiplyCalculator = new NumberCalculator(Multiply); 11 delegates = addCalculator; 12 delegates += multiplyCalculator; 13 GetNum(delegates); 14 15 } 16 17 //加法 18 static void Add(int a) 19 { 20 num1 = a + num1; 21 } 22 //乘法 23 static void Multiply(int c) 24 { 25 num1 = num1 * c; 26 } 27 28 //调用委托得到结果及打印 29 static void GetNum(NumberCalculator numberCalculator) { 30 numberCalculator(num1); 31 Console.WriteLine(num1); 32 } 33 }