1. 程式人生 > >C#委托和事件

C#委托和事件

ng2 div log pan func fun str clas region

        #region 委托、事件
        static void ChineseGreeting(string name)
        {
            Console.WriteLine("早上好," + name);
        }
        static void EnglishGreeting(string name)
        {
            Console.WriteLine("Good Morning," + name);
        }
        delegate void GreetDelegate(string
name); static void Greeting1(string name, GreetDelegate greetFunc) { greetFunc(name); } static void Greeting2()//綁定方法 { GreetDelegate dele1 = ChineseGreeting; dele1 += EnglishGreeting; Greeting1("Zheng", dele1); dele1
-= ChineseGreeting; dele1("Jonathan"); } //public event GreetDelegate del2; #endregion

C#委托和事件