Proposal: allow NRTs in patterns #9287
Unanswered
masonwheeler
asked this question in
Language Ideas
Replies: 3 comments 5 replies
-
An initial issue here is the grammar prefix overlap for |
Beta Was this translation helpful? Give feedback.
3 replies
-
How about: |
Beta Was this translation helpful? Give feedback.
1 reply
-
This proposal would put the language in an inconsistent state compared to nullable value types, where this syntax is already legal and evaluates to false for nulls: object o = null;
Console.WriteLine(o is int?); // Prints: False I don't like the idea of |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is a very simple proposal: it's currently a compile error to use a NRT in a pattern-matching expression. (ie.
x is MyType?
) This should be allowed. The semantics would be that either a null or aMyType
would be a valid match for this pattern.The main value in this is that the successful match could then be assigned to a variable of type
MyType?
. This is not currently possible; if you sayx is MyType mt or null
you get a compile error because you can't declare a variable inside anor
pattern.Beta Was this translation helpful? Give feedback.
All reactions