您现在的位置是:首页
>
扩展卷不能选 C# 扩展方法使用
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();

Response Write( 值 + count);
}
输出 值
lishixinzhi/Article/program/net/201311/13177 很赞哦! (1055)