Wednesday, April 27, 2011

What is double question mark in C#?

 The ?? operator is called the null-coalescing operator.
It returns the left-hand operand if it is not null; otherwise it returns the right operand


        int? x = null;
        // y = x, unless x is null, in which case y = -1.
        int y = x ?? -1
        // In here y = -1
        x = 1;
        y = x ?? -1
        // In here y = 1



Reference:

No comments:

Post a Comment