哪种方式确实是检查空字符串的最快方法,并且有任何特定情况需要任何特定的.
1. String.IsNullOrEmpty()
2. str == null
3. str == null || str == String.Empty
4. str == null || str == ""
5. str == null || str.length == 0
Run Code Online (Sandbox Code Playgroud)
你也关心空白吗?
如果空格有效,则使用String.IsNullOrEmpty,否则使用String.IsNullOrWhiteSpace(在 .Net 4.0 或更高版本中)。后者相当于,但性能更高,String.IsNullOrEmpty(value) || value.Trim().Length == 0;
请参阅http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace.aspx
| 归档时间: |
|
| 查看次数: |
17099 次 |
| 最近记录: |