您现在的位置是:首页 >

扩展卷不能选 C# 扩展方法使用

火烧 2021-07-09 18:40:50 1055
C# 扩展方法使用   为指定类型扩展方法  定义类Cla    u lic tatic cla Cla //必须为 tatic类 且不能包含构造函数  {  /// lt ummary gt   /

C# 扩展方法使用  

  为指定类型扩展方法

  定义类Class

  public static class Class                                   //必须为static类 且不能包含构造函数

  {

  /// <summary>

  /// 返回指定字符串中以 $ 为分隔的数组长度

  /// </summary>

  /// <param name= value >string值</param>

  /// <returns>整型</returns>

  public static int ArrayListLenght(this string value)

  {

  int len = ;

  if (value IndexOf( $ ) >= )

  {

  len = value Split( $ ) Length;

  }

  return len;

  }

  }

  页面调用

  protected void Page_Load(object sender EventArgs e)

  {

  string sValue = bbsdfdfd$ssbbsdfdfd$ss ;

  int count = sValue ArrayListLenght();

扩展卷不能选 C# 扩展方法使用

  Response Write( 值 + count);

  }

  输出 值

lishixinzhi/Article/program/net/201311/13177  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码