您的位置:首页 > 其它

自写扩展方法

2015-08-16 21:25 381 查看
有时候我们需要一个方法,但是.net没有提供,我们需要自己写个扩展方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CsTest
{
static class kuozhan
{
public static string se(this string d)
{
return d.Remove(0,2);
}
public static string  isou(this int ds)
{
if (ds%2==0)
{
return "是个偶数";
}
else
{
return "不是偶数";
}
}
}
}


直接调用

class Program
{
static void Main(string[] args)
{
string str = "Hello World!";
str.se();
int b = 67;
b.isou();

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: