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

posted on 2014-05-08 18:42  bin10.dll  阅读(105)  评论(0)    收藏  举报