C# Pattern Matching
Pattern matching 支持 is 和 switch 表达式,它们的作用是检查 object 和它的 properties 是否满足 pattern。另外可以用 when 关键字为 pattern 指定附加规则。
is expression
is pattern expression 是 is operator 的扩展。
switch expression
意义
在面向对象编程中,多态 是在 objects 上实现 method dispatch。
Pattern matching 是 properties 上实现 method dispatch。