判断字符串是否为空的几种方法


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日


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM