C # 7 pattern matching semantics

I have two blocks of code that I would like to think equal:

Block first if IF code

Then the same thing, but converted to a switch type by type. (sorry for the unsuccessful reddish red markers of Resharper, Resharper still doesn’t understand this)

SWITCH based code

Switch-based code will throw a Null reference exception in the first return Actor.Done, which is not null.

Is this a template matching error or is there some kind of semantics that I'm missing here?

[edit] I found a fix for it.

Change this:

case MessageEnvelope env:

to

case MessageEnvelope _:
    var env = m as MessageEnvelope;

Does it all. So this leaves me wondering if these lines should be the same?

+2
source share
1 answer
+3

Source: https://habr.com/ru/post/1696134/


All Articles