MVC ---- 如何扩展方法

先定义一个扩展类:

public static class StringExtend
{
  //扩展一个string的方法
  public static bool IsNullOrEmpty(this string s)
  {
    return string.IsNullOrEmpty(s);
  }
}

再用的时候如果扩展类和实用类是在同一个文件夹中,直接点扩展方法就可以了。如果不在那就要引用。

public void stringBuf(string str){
  //这样使用
  str.IsNullOrEmpty();

}
原文地址:https://www.cnblogs.com/youmingkuang/p/6275173.html