Welcome to SofiaDev.Org's Blogs Sign in | Join | Help

Playing with strings (part 2 of n)

Do you know, that there's a build-in check for empty/null strings in .NET 2.0?

So instead of doing this:

 

string strValue = "";

if (null == strValue || strValue.Length <= 0)
{
   //do something
}

You can do this:


string
strValue = "";

if (string.IsNullOrEmpty(strValue))

   //do something
}

Basically the method implementation looks like this:

public static bool IsNullOrEmpty(string value)

   if (value != null
   { 
      return (value.Length == 0); 
   
}

   return true;
}

Happy coding!!!

Published 21 Януари 2007 22:52 by branimir

Comments

No Comments

Anonymous comments are disabled