一、空值判断效率
string s = "";
- if(s == ""){}
- if(s == string.Empty){}
- if (string.IsNullOrEmpty(s)) {}
- if(s != null && s.Length ==0) {}
- if((s+"").Length == 0){}
1,2最慢;3较快;4,5最快
1,2几乎没区别;4,5几乎没区别
二、空值和null判断
- if (string.IsNullOrEmpty(s)) {}
- if(s == null || s.Length == 0) {}
- string.IsNullOrWhiteSpace性能更高
推荐用2,3
原文地址:https://www.cnblogs.com/wsq-blog/p/10663815.html
时间: 2024-10-13 06:02:53