可能重复:
如何检查String是否为null
我需要能够null在字符串中检查一个值.我目前所知道的最好的方法是String.IsNullOrEmpty(),它不适合我们想要做的事情(string.empty值是允许的,nulls不是).有没有人有什么建议?
Sam*_*ica 11
只需比较你的字符串 null
bool stringIsNull = mystring == null;
Run Code Online (Sandbox Code Playgroud)
这是你的扩展方法
public static class ExtensionMethods
{
public static bool IsNull(this string str)
{
return str == null;
}
}
Run Code Online (Sandbox Code Playgroud)
您检查是否有任何其他变量为null的方法与检查相同:
if(variable == null)
{
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1726 次 |
| 最近记录: |