
测试结果
Debug.Log(s == null);//true
Debug.Log(ss == null);//false
Debug.Log(sss == null);//false
Debug.Log(string.IsNullOrEmpty(s));//true
Debug.Log(string.IsNullOrEmpty(ss));//false
Debug.Log(string.IsNullOrEmpty(sss));//true
测试总结: 如果判断字符串 是否为空null 只要字符串没有被赋值那么就是null,被赋值了就不为null
string.IsNullOrEmpty(sss) Empty是空 如果内容为空就是空
还有一个API是 string.IsNullOrWhiteSpace这个API 如果是多个空格得也会返回true 相当于空

博客展示了字符串空值判断的测试结果,包括判断字符串是否为 null 以及使用 string.IsNullOrEmpty 和 string.IsNullOrWhiteSpace 方法。总结指出未赋值的字符串为 null,赋值则不为 null;string.IsNullOrEmpty 判断内容为空的情况;string.IsNullOrWhiteSpace 对多个空格也视为空。
1434

被折叠的 条评论
为什么被折叠?



