通用计算机语言,数据类型一般分为值类型和引用类型,C#也不例外。在C#中,值类型分为简单类型,结构类型,枚举类型;引用类型分为类,代表,数组,接口。下面用代码说明“代表”的使用。using System; namespace Welcome { class Program { /** * 申明两个代表 */ delegate int Delegate1(); delegate void Delegate2(); static void Main(string[] args) { Delegate1 d1 = new Delegate1(print1); Delegate2 d2 = new Delegate2(print2); d1(); d2(); Console.ReadLine(); } private static int print1() { Console.WriteLine("111111111111"); return 0; } private static void print2() { Console.WriteLine("222222222222"); } } }
结果: