When returning an object that may be null, but I shouldn't usually go in with (what is its own name ?!) a very surprised operator: ?? So.
return hazaa ?? new Hazaa();
The problem occurs when I return the property of an object (if it exists) and another default value. Not that the nullness check was done on the parent object. Today I like it.
return hazaa != null ? hazaa.Property : String.Empty;
I think this is a less than optimal syntax, and I would like it to be more compact (but still easy to understand, given that the property is implemented accordingly).
return (hazaa ?? new Hazaa()).Property;
However, I don't like parentheses, and I'm looking for syntax that omits them, still compact. Is there such a thing in C #? I am looking for something like this.
return hazaa ?.Property :String.Empty;
And, turning over the thought, something like that.
return hazaa ?.Property :.BackUpProperty;
I can create my own properties layer that gives me this behavior, but that just hides the problem. :)
source share