扩展方法

例如:扩展int方法

  //staic静态类
public static class Int32Extension{
  //静态方法
  public static string FormatForMoney(this int value){
    return Value.tostring("");
   }
}

声明完扩展方法后,在vs中会自动侦测,直接调用即可

  int i=100;

  i.FormatForMoney();

若要引用不同命名空间类的扩展方法,记得加上using引用,否则编译器无法找到扩展方法

原文地址:https://www.cnblogs.com/william-CuiCui0705/p/8303372.html