"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:E6**********************************@microsof t.com...
Hi,
In case you want to test for an empty string use
if(string.IsNullOrEmpty("Hello World"))
{
// string is either null or ""
}
--
Happy Coding!
Morten Wennevik [C# MVP]
I would be hard pressed to use IsNullOrEmpty to check for an empty string.
This is due to the fact that Null means the absence of a value while an
empty string is a string whose value contains no characters (hence empty
string). IsNullOrEmpty is the same as:
("Hello World" == null || "Hello World" == string.Empty)
while checking for an empty string is:
("Hello World" == string.Empty)
Therefore, they are not functionally equivalent. Although, I would usually
use IsNullOrEmpty in place of just an empty string check in *most* cases.
Some cases, you may not want to check for null, maybe you need to do
something different for null strings (raise an exception?) compared to empty
strings (allowed so no exception?).
HTH,
Mythran