1:扩展方法是一个静态方法,扩展的类型必须用this指定
例如:对string 进行扩展
public static class EString
{
public static int Expand(this string t)
{
return t;
}
}
//调用
static void Main(string[] args)
{
string str = "welcome!";
str.Expand();
}
C#中的扩展方法
于 2021-03-26 01:09:06 首次发布