c#委托的定义和使用

118 阅读1分钟

用delegate+返回值类型定义委托,委托的参数为需要使用的方法

 class Program
    {
        private delegate string getastring();
        static void Main(string[] args)
        {
           
            int x = 40;
            getastring a = new getastring(x.ToString);
            string s = a();
            Console.WriteLine(s);
            Console.ReadKey();
        }
    }