多播委托

xiaoxiao2021-02-28  64

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 多播委托 { //public delegate void MyDel(); public delegate int MyDel(); class Program { static void Main(string[] args) { #region 无参数委托 //MyDel mdl = M1; //mdl += M2; //mdl += M3; //mdl += M4; //mdl -= M2; //mdl(); #endregion MyDel mdl = T1; mdl(); int sum = mdl.Invoke(); Console.WriteLine(sum); mdl += T2; mdl += T3; int result = mdl(); Console.WriteLine(result); Console.ReadKey(); } public static int T1() { return 1; } public static int T2() { return 2; } public static int T3() { return 3; } public static void M1() { Console.WriteLine("1"); } public static void M2() { Console.WriteLine("2"); } public static void M3() { Console.WriteLine("3"); } public static void M4() { Console.WriteLine("4"); } } }
转载请注明原文地址: https://www.6miu.com/read-35845.html

最新回复(0)