您希望在asp.net应用程序的公共类中放入哪种方法?在几乎所有的asp.net项目问题中都会用到的一个常用函数。
发布于 2010-09-01 18:34:21
这些应该一直存在:
/// <summary>
/// Answers true if this String is not null or empty
/// </summary>
public static bool HasValue(this string s)
{
return !string.IsNullOrEmpty(s);
}
/// <summary>
/// Answers true if this String is either null or empty.
/// </summary>
public static bool IsNullOrEmpty(this string s)
{
return string.IsNullOrEmpty(s);
}因为返回到string.IsNullOrEmpty(value)类型而不是继续,感觉非常不自然,至少对我来说是这样。对我来说,爱它或恨它(我就是那个使用它的人…)阅读起来很清楚,并且为我节省了大量的时间、击键和挫败感。
是的,这可能很快就会关闭,但是,好吧,我感觉像是在抱怨缺乏基本的字符串函数:)
发布于 2010-09-01 18:39:25
public static bool TryFindControl<T>(this Control control, string id, out T foundControl) where T : class
{
return (foundControl = control.FindControl(id) as T) != null;
}发布于 2010-09-01 18:33:40
首先,这是我在几乎所有asp.net项目中使用的函数函数:检查字符串是否为数字
public bool IsNumeric(string str)
{
if (str == null || str.Length == 0)
return false;
System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
byte[] bytestr = ascii.GetBytes(str);
foreach (byte c in bytestr)
{
if (c < 48 || c > 57)
{
return false;
}
}
return true;
}https://stackoverflow.com/questions/3617111
复制相似问题