Search code examples
c#.netrobustness

Null and blank values


What's the best way of writing robust code so that a variable can be checked for null and blank.

e.g.

string a;

if((a != null) && (a.Length() > 0))
{
    //do some thing with a
}

Solution

  • For strings, there is

    if (String.IsNullOrEmpty(a))