判斷字符串是否爲空的幾種方法

string str = string.Empty;
if (str == "")
{ }
else { }

if (str == string.Empty)
{ }
else { }

if (str.Length == 0)//效率最高
{ }
else { }

if (string.IsNullOrEmpty(str))//可讀性更強
{ }
else { }

if (string.IsNullOrWhiteSpace(str))
{ }
else { }

 

 

----------------------------------------------------------------------------
創建於2017年2月24日

整理於2017年11月27日

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章