摘要: 扩展方法使您能够向现有类型“添加”方法,而无需创建新的派生类型、重新编译或以其他方式修改原始类型。我们来为String类型定义一个简单的扩展方法:public static class Extensions{ public static void SayHello(this String name) { Console.WriteLine("Hello {0}",name); }}之后,我们可以在main函数中这样使用扩展方法:static void Main(string[] args){ String s = "Wade"; s.SayHello() 阅读全文
posted @ 2011-06-17 13:19 heqichang 阅读(1935) 评论(2) 推荐(0) 编辑