/// <summary>
/// String.IsNullOrEmpty() and String.IsNullOrWhiteSpace()
/// String.IsNullOrEmpty()
/// 判断字符串是否为null或者empty,代表有,null值和""
/// 特殊" "表示有一个空串,判断后会返回一个false
///
/// String.IsNullOrWhiteSpace()
/// 判断字符串是否为null或者空白
/// 代表有null," ",""
/// 这样表示的都不满足
/// </summary>
/// <param name="args"></param>
string[] testValues = { "admin", null, "", " ", "test" };
foreach (string item in testValues){
Console.WriteLine("IsNullOrEmpty:" + string.IsNullOrEmpty(item));
Console.WriteLine("IsNullOrWhiteSpace:" + string.IsNullOrWhiteSpace(item));
}
string lengths = ""; //返回长度为“0”
string whiteLength = " "; //返回长度为“1”
Console.WriteLine(lengths.Length+"\t"+whiteLength.Length); //0,1
//都会返回True,表示当前的字符串都是空串和null
Console.WriteLine(string.IsNullOrWhiteSpace(lengths)+"\t"+string.IsNullOrWhiteSpace(whiteLength));
备注:前面一个是判断当前字符串是否为null值和空白字符串,后面一个是判断当前字符串是否为null值和空白("" ," "),结果都会返回True和False