C# 为String类型增加方法

namespace MyExtensionMethods
{
    public static class MyExtensions
    {
        public static int MyGetLength(this System.String target)
        {
            return target.Length;
        }
    }
}



使用时,需要引入这个名字空间,引用如下:

string str = "dafasdf";
int len = str.MyGetLength();

 

posted @ 2012-05-06 03:32  你妹的取名这么难  阅读(2004)  评论(0编辑  收藏  举报