allow conditional operator to infer foo? when something ? foo : null
#9592
-
Take a look at this code: var condition = /* something */ ;
var number = 123;
var want = condition ? number : null; I think it's reasonable to extrapolate the return type of that expression as int?, and null here should be treated as (int?)null, and when changing to
It's not a big problem, but I think we can improve on this. Actually my thoughts are unified 'condition?' foo: null' works when foo is a value type and foo is a reference type. Because of the following code: var condition = /* something */ ;
var uri = new Uri("https://microsoft.com");
var want = condition ? uri : null; can be compiled, and |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Duplicate of #33. |
Beta Was this translation helpful? Give feedback.
Duplicate of #33.