using System;
namespace 委托和事件
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Action action = One;
            action += Two;
            action += Three;
            Delegate[] delegates = action.GetInvocationList(); //返回委托挂接的方法,通过他可以控制委托方法执行顺序
            foreach (Action delegateAction in delegates)
            {
                try
                {
                    delegateAction();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.Read();
        }
        private static void One()
        {
            Console.WriteLine("调用:方法一");
            throw new Exception("Err in one");
        }
        private static void Two()
        {
            Console.WriteLine("调用:方法二");
        }
        private static void Three()
        {
            Console.WriteLine("调用:方法三");
        }
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-12-20
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
相关资源
相似解决方案