首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 得出判断是不是为空的最好方法

2012-12-19 
C# 得出判断是否为空的最好方法1.最普遍、最直接的方法string Input Yours Input Msgif (Input )

C# 得出判断是否为空的最好方法

1.最普遍、最直接的方法
string Input = "Yours Input Msg";
if (Input == "");
???????????
2.使用String.Empty
string Input = "Yours Input Msg";
if (Input == String.Empty);

?

3.使用string.Length
string Input = "Yours Input Msg";
if (Input.Length == 0);

?

借鉴一些文章得下好的判断方法,省空间,省内存,效率高

这样,比起Input == ""这个方法,效率大约提高13-30多倍(因为有短路运算),空间却只要1/7。

因此这些方法中判断字符串是否为空的最佳方法是:

if(desStr!=null && desStr.Length==0)

?

热点排行