using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharp_Learn_001
{
        //1 定义委托
        public delegate void GreetingDelegate(string name);

        class Program
        {
                //1.1 Func
                private static void EnglishGreeting(string name)
                {
                        Console.WriteLine("Moniring, " + name);
                }
                //1.2 Func
                private static void ChineseGreeting(string name)
                {
                        Console.WriteLine("早上好, " + name);
                }
                //2.1 DelegateFunc
                private static void GreetPeople(string name, GreetingDelegate MakeGreeting)
                {
                        MakeGreeting(name);
                }

                //3. main
                static void Main(string[] args)
                {
                        GreetPeople("Jimmy Yang", EnglishGreeting);
                        GreetPeople("杨麒", ChineseGreeting);
                        Console.ReadKey();
                }

        }
}
委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递,这种将方法动态地赋给参数的做法,可以避免在程序中大量使用If-Else(Switch)语句,同时使得程序具有更好的可扩展性。