Phil Phil - 19 days ago 6
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)) {
    ...
}