一、空值判斷效率
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