C#基础进阶

观看C#高级教程进行学习。巩固基础,进阶学习。

1.委托

把方法当做参数来传递就是委托。委托的关键字是delegate。

 class Program
    {
        private delegate string GetString();
        static void Main(string[] args)
        {
        int x=40;
        GetString a = x.ToString;//方法签名
        string t = a();
        Console.WriteLine("{0}", t);
        Console.ReadKey();
        }
    }
委托获取X的String

Invoke方法也可以调用委托所引用的方法。

猜你喜欢

转载自www.cnblogs.com/cdjbolg/p/11896775.html