>String.IsNullOrEmpty

>

Instead of

    if( null == myString || string.Empty == myString ){…

one can use

    if( string.IsNullOrEmpty( myString ) ){…

There is nothing magic about it, just a more readable, and hence less error prone, syntax.

It would be nice of someone could solve the

    if( null == myCustomer.Address || null == myCustomer.Address.City || null == myCustomer.Address.City.Name ){…

-problem.

In Dotnet4 there will be a method similar to IsNullOrEmpty which also checks for whitespace.  It should come in handy.

2 Responses to “>String.IsNullOrEmpty”

  1. Claes Mogren says:

    >I like the ?.-operator in groovy.

    if(null == myCustomer?.Address?.City?.Name){

    This would be true if any of myCustomer, Address, City or Name was null, without throwing a nullpointer exception. Something for C# 5?

  2. mblund says:

    >Claes: Of course that you was the first one to comment this :-)

    In Java we have to wait until v8
    But hey, you don't pass around lots of null values anyway, do you?

Leave a Reply