?? Null-Coalescing Operator

suggest change

The Null-Coalescing operator ?? will return the left-hand side when not null. If it is null, it will return the right-hand side.

object foo = null;
object bar = new object();

var c = foo ?? bar;
//c will be bar since foo was null

The ?? operator can be chained which allows the removal of if checks.

//config will be the first non-null returned.
var config = RetrieveConfigOnMachine() ??
             RetrieveConfigFromService() ??
             new DefaultConfiguration();

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents