In Javascript I can do this:
var myVar = returnNull() || new MyObject();
In C# I am currenly doing this:
var myVar = returnObjec
You can use ?? Operator (C# Reference) operator like;
var myVar = returnObjectOrNull() ?? new MyObject();
The
??
operator is called the null-coalescing operator and is used to define a default value for nullable value types or reference types. It returns the left-hand operand if the operand is not null; otherwise it returns the right operand.