Answer the question
In order to leave comments, you need to log in
Why doesn't C# support this pattern matching?
why can't I write like this:
var matched = obj is { Id: variable }
are there any libraries that will allow me to do this?
Answer the question
In order to leave comments, you need to log in
C# just doesn't know how to use variables in pattern matching and switch-case.
In this case, you can write like this:
Well, or like this, if the case is more complex:
var matched = obj != null && obj.Id == variable;
var matched = obj is { Id: var id} && id == variable;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question