namespace out_ref { //声明一个委托 public delegate void MyDelegate(); class Program { static void Main(string[] args) { MyDelegate mdl = Say; Do(mdl); Console.ReadKey(); } static void Do(MyDelegate mdl) { mdl(); } static void Say() { Console.WriteLine("哈哈"); } } }
namespace out_ref { //声明一个委托 public delegate int MyAdd(int n1,int n2); class Program { static void Main(string[] args) { Do(Sum); Console.ReadKey(); } static void Do(MyAdd myadd) { int sum = myadd(1,3); Console.WriteLine(sum); } static int Sum(int n1,int n2) { return n1 + n2; } } }
namespace out_ref { //委托占位案例 public delegate void Myadd(); class Program { static void Main(string[] args) { Do(Dafeiji); Console.ReadKey(); } static void Do(Myadd myadd) { Console.WriteLine("我正在吃饭...."); myadd(); Console.WriteLine("我正在睡觉...."); } static void Play() { Console.WriteLine("我在玩游戏...."); } static void Dafeiji() { Console.WriteLine("我正在打飞机...."); } } }
时间: 2024-10-25 19:21:24