I started a new Interview Questions Blog where I will be posting solutions to commonly asked technical programming interview questions. Currently I have about 50 coding questions asked in programming interviews. Hopefully, I will be adding more questions and solutions progressively.
The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.
if (myObject == null)
myObject = new MyClass();
The above code can be represented using the one-liner below.
return myObject ?? new MyClass();