namespace ConsoleApp1{class Program{delegate int myDelegate(int t); //定义委托  返回值类型 入参类型static  int num = 10;static void Main(string[] args){myDelegate myDelegate1 = new myDelegate(Test1); //实例化委托myDelegate myDelegate2 = new myDelegate(Test2); //实例化委托int theOne = myDelegate1(10); //调用委托,传入参数10int theTwo = myDelegate2(3); //调用委托,传入参数3Console.WriteLine(\"theOne:\"+theOne);Console.WriteLine(\"theTwo:\" + theTwo);Console.ReadLine();}static int Test1(int p){num += p;return num;}static int Test2(int p){num *= p;return num;}}}
运行控制台程序,打印结果如下:
theOne:20
theTwo:60
 爱站程序员基地
爱站程序员基地
![(原创)[C#] 一步一步自定义拖拽(Drag&Drop)时的鼠标效果:(一)基本原理及基本实现-爱站程序员基地](https://aiznh.com/wp-content/uploads/2022/07/20220721231016-62d9dcd85c40b-220x150.gif)

