拓展方法

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

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

//调用
string s="hello";
s.Foo();

 

posted @ 2017-11-12 12:27  fight139  阅读(147)  评论(0编辑  收藏  举报