-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Conditional-expression/access syntax refinement.
- Specification: https://github.com/dotnet/csharplang/blob/main/proposals/conditional-operator-access-syntax-refinement.md
- Discussion: [Proposal Discussion]: Conditional operator/access syntax refinement #9780
Summary
Introduce whitespace-sensitive parsing rules to eliminate ambiguity between the conditional operator (?:)
and null-conditional access operators (?. and ?[). This change requires that tokens in null-conditional
operators must be adjacent with no intervening characters, while conditional operators with certain operand
patterns must have whitespace or comments between the ? and the subsequent token.
For example: a?[ will always be interpreted to be the start of a conditional index into a (e.g. a?[b]). In other words, indexing into a with some arguments that follow the [ if a is non-null. Whereas a? [ will always be interpreted to be the start of a condition expression (e.g. a ? [b] : ...). So a test if a is true or not, and returning a collection expression if so.