Search code examples
c#.netstringnullis-empty

Easier way of writing null or empty in C#?


I'm sure I've missed something here. With a certain project I need to check if a string is null or empty.

Is there an easier way of writing this?

if (myString == null || myString == "")
{
   ...

Solution

  • Yes, there's the String.IsNullOrEmpty helper method for exactly this already:

    if (String.IsNullOrEmpty(myString)) {
        ...
    }