Unique ways to use the Null Coalescing operator
- by Atomiton
I know the standard way of using the Null coalescing operator in C# is to set default values.
string nobody = null;
string somebody = "Bob Saget";
string anybody = "";
anybody = nobody ?? "Mr. T"; // returns Mr. T
anybody = somebody ?? "Mr. T"; // returns "Bob Saget"
But what else can ?? be used for? It doesn't seem as useful as the ternary…