拓展方法

1.拓展方法为类提供额外的方法,拓展方法在静态类中定义,定义为静态方法,

public static class StringExt{
    public static void Foo(this string s){
       Console.Write(s);
    }
}    

//调用
string s="hello";
s.Foo();
原文地址:https://www.cnblogs.com/zhuxiang1633/p/7821368.html