String.IsNullOrEmpty()函数的一个误区

从用vs2005开始,很多人在判断string类型时.喜欢用String.IsNullOrEmpty()来完成判断为""的情况.

但今天无意间发现.其中根本不包括我们潜意思中想当然有的Trim()功能,所以会认为

string.IsNullOrEmpty("  ")为true,其实是为false.

Published 06 June 2007 09:44 AM by Kamte

Comments

# jawance said on 07 June, 2007 08:36 AM

好像1个空格 !=String.Empty哦。

string AA=" ";

string.IsNullOrEmpty(A) =false

string.IsNullOrEmpty(Trim(A)) =true

# wicky said on 08 June, 2007 03:23 PM

Inside the method:

[code]

public static bool IsNullOrEmpty(string value)

{

   if (value != null)

   {

       return (value.Length == 0);

   }

   return true;

}

[/code]