Champion: target-typed conditional expression (VS 16.8, .NET 5)
- [X] Proposal added (https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/target-typed-conditional-expression.md)
- [x] Discussed in LDM 2019-04-22
- [X] Decision in LDM (Approved for C# 8)
- [ ] Finalized (done, rejected, inactive)
- [ ] Spec'ed
This was split from https://github.com/dotnet/csharplang/issues/2389 and is being treated as a separate feature
For a conditional expression c ? e1 : e2, when there is no common type for e1 and e2, we define a new conditional expression conversion that permits an implicit conversion from the conditional expression to any type T for which there is a conversion-from-expression from e1 to T and also from e2 to T. It is an error if a conditional expression neither has a common type between e1 and e2 nor is subject to a conditional expression conversion.
Relates to https://github.com/dotnet/csharplang/issues/2701 (target-typed new[])
Could this also apply to the ?? operator as well?
@YairHalberstadt This proposal is for the ?: operator only.
@gafter
I understand, but is there any reason not to do the equavelent for ??. I would find it extremely useful.
Should I open a new proposal for it?
I don’t know. I have not thought about doing something for ??. The main reason not to do something in general is the balance between limited resources and limited benefit.
If I were to offer to implement it, would that make a difference?
@YairHalberstadt Without a proposed specification, I have no idea. I think we'd want to review the proposed specification to decide if it were something we want or not.
I have suggested a specification at #2473
Would love to see this feature added!