0
点赞
收藏
分享

微信扫一扫

C#的多播委托

624c95384278 2022-02-22 阅读 47
 class Program {
        static void Test1()
        {
            Console.WriteLine("test1");
            //throw new Exception();
        }

        static void Test2()
        {
            Console.WriteLine("test2");
        }
        static void Main(string[] args) {
            //多播委托
            Action a = Test1;
            //a = Test2;
            a += Test2;//表示添加一个委托的引用 
            //a -= Test1;
            //a -= Test2;
            //if(a!=null)
            //    a();//当一个委托没有指向任何方法的时候,调用的话会出现异常null

            Delegate[] delegates = a.GetInvocationList();
            foreach (Delegate de in delegates)
            {
                de.DynamicInvoke();
            }
            Console.ReadKey();
        }
    }
举报

相关推荐

多播委托

C#——委托

C#中的委托

C#之委托

C#委托总结

C#事件委托

0 条评论