C# 扩展方法

来源:互联网 发布:教舞蹈的软件 编辑:程序博客网 时间:2024/06/14 00:13

C#的扩展方法真的非常简单好用:相关链接:http://www.cnblogs.com/suger/archive/2012/05/13/2498248.html

使用例子如下:

 

譬如说我要在String这个类中添加一个我自己的方法

申明静态类,然后静态方法,注意第一个参数必须家this关键字

    public static class Extension    {        public static string appendStringName(this String s, String name)        {            return s+name;        }    }


调用

Console.WriteLine("123".appendStringName("333"));


 

0 0
原创粉丝点击