delegate

 class Program
    {
        private delegate string GetAString();
        private delegate string SayHi(string name);
        static void Main(string[] args)
        {
            Core(SayHiToYangc, "yangc");
            Console.ReadLine();
        }

        public static string SayHiToYangc(string name = "yangc")
        {
            return "你好 " + name;
        }

        public static string SayHiToKevin(string name = "C·Yang")
        {
            return "Hello " + name;
        }

        static void Core(SayHi sh, string str)
        {
            string result = sh(str);
            Console.WriteLine(result);
        }
    }

你可能感兴趣的:(delegate)