Petes techie blog

A blog written for two people. Me and You.

Null-coalescing Operator in C#

| Comments

I always like elegant looking code. I find it very ugly having if statements to compare to null. In c# you can use the ?? operator which basically says if left hand side is null then use right hand side else use left hand side.

Example:

string r = null;

Console.Write(r ?? “”);

sweet.