Phil Phil - 5 months ago 39
C# Question

Easier way of writing null or empty?

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

Is there an easier way of writing this?

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

Answer

Yes, there's a helper method for exactly this already:

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