Tuesday, April 1, 2008

String.IsNullOrEmpty method

Returns true if the string passed in is null or empty. Otherwise returns false.
Before:
if (name == null || name == string.Empty)) 
{
     return "Please enter a name."; 
}
After:
if (string.IsNullOrEmpty(name)) 
{     
    return "Please enter a name."; 
}
More Info: MSDN: String.IsNullOrEmpty