一、概述 C#中判断字段或者字符串是否为空或者NULL的时候,我们通常使用IsNullOrEntity和IsNullOrWhiteSpace函数进行判断,但是这两个函数在大部分情况得出的结果是一致的,但是有些情况还
          一、概述
C#中判断字段或者字符串是否为空或者NULL的时候,我们通常使用IsNullOrEntity和IsNullOrWhiteSpace函数进行判断,但是这两个函数在大部分情况得出的结果是一致的,但是有些情况还是有区别的。
二、代码实现
            {
                Console.WriteLine($"IsNullOrEmpty判断字符串默认为空:{String.IsNullOrEmpty(string.Empty)}");
                Console.WriteLine($"IsNullOrEmpty判断字符串为NULL:{String.IsNullOrEmpty(null)}");
                Console.WriteLine($"IsNullOrEmpty判断字符串空格:{String.IsNullOrEmpty()}");
                Console.WriteLine($"IsNullOrEmpty判断字符串为转义字符\\t:{String.IsNullOrEmpty("\t")}");
                Console.WriteLine($"IsNullOrEmpty判断字符串为转义字符\\n:{String.IsNullOrEmpty("\n")}");
                Console.WriteLine($"IsNullOrEmpty判断字符串不为空:{String.IsNullOrEmpty("hellow")}");
            }
            {
                Console.WriteLine($"IsNullOrWhiteSpace判断字符串默认为空:{String.IsNullOrWhiteSpace(string.Empty)}");
                Console.WriteLine($"IsNullOrWhiteSpace判断字符串为NULL:{String.IsNullOrWhiteSpace(null)}");
                Console.WriteLine($"IsNullOrWhiteSpace判断字符串空格:{String.IsNullOrWhiteSpace("      ")}");
                Console.WriteLine($"IsNullOrWhiteSpace判断字符串为转义字符\\t:{String.IsNullOrWhiteSpace("\t")}");
                Console.WriteLine($"IsNullOrWhiteSpace判断字符串为转义字符\\n:{String.IsNullOrWhiteSpace("\n")}");
                Console.WriteLine($"IsNullOrWhiteSpace判断字符串不为空:{String.IsNullOrWhiteSpace("hellow")}");
            }
四、区别
- 
返回结果
value IsNullOrEmpty IsNullOrWhiteSpace string.Empty true true null true true " " false true \t false true \n false true hellow false false 
