Skip to content

Which kind of pattern matching is this ? #50083

Answered by svick
a510 asked this question in Q&A
Discussion options

You must be logged in to vote

So, the confusing part here is ((double)i). The language understand this as a positional pattern, which can be used to deconstruct tuples, or other types that have the Decontruct method. A more common use of such pattern would be something like var tuple = (1, 2); if (tuple is (3, 4)) ....

The only subpattern of the positional pattern is the constant pattern (double)i. A more common use of a constant pattern would be double x = 1.0; if (x is 0.0) ....

Though it does look confusing, so I wouldn't suggest you actually write such code and I can't think of a situation when you would want to anyway.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@a510
Comment options

Answer selected by a510
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants