Possible Duplicate:
Is there an “opposite” to the null coalescing operator? (…in any language?)
Is there a more concise way of writing the third line here?
int? i = GetSomeNullableInt();
int? j = GetAnother();
int k = i == null ? i : j;
I know of the null coalescing operator but the behaviour I’m looking for is the opposite of this:
int k == i ?? j;
Sneaky – you edited it while I was replying. 🙂
I do not believe there is a more concise way of writing that. However, I would use the “HasValue” property, rather than == null. Easier to see your intent that way.
(BTW – k has to be nullable, too.)