在.NET中,这是最好的,mystring.Length == 0或了mystring ==的String.Empty? [英] In .NET, which is best, mystring.Length == 0 or mystring == string.Empty?

查看:167
本文介绍了在.NET中,这是最好的,mystring.Length == 0或了mystring ==的String.Empty?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/10230/checking-for-string-contents-string-length-vs-empty-string">Checking字符串的内容?字符串长度VS空字符串

Possible Duplicate:
Checking for string contents? string Length Vs Empty String

在.NET中,这是最好的,

In .NET, which is best,

if (mystring.Length == 0)

if (mystring == string.Empty)

看来,这些将有相同的效果,但这将是最好的幕后?

It seems that these would have the same effect, but which would be best behind the scenes?

推荐答案

我preFER

String.IsNullOrEmpty(myString)

以防万一它包含空值。

Just in case it contains a null value.

这篇关于在.NET中,这是最好的,mystring.Length == 0或了mystring ==的String.Empty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆