c#基础介绍四
委托
using System; namespace bin { public class test { public delegate string GetAString(); public static void Main() { int x=10; GetAString firstString=new GetAString(x.ToString); Console.WriteLine(firstString()); //上句和下面这句类似。 //Console.WriteLine(x.ToString()); } } }
其语法和方法的定义类似,只是没有方法体,前面要加上关键字 delegate
浙公网安备 33010602011771号