Last active
June 19, 2018 15:55
Star
You must be signed in to star a gist
C# 8: extended pattern matching with the switch expression - property pattern, recursive pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string M3(Shape shape) | |
=> shape switch | |
{ | |
CombinedShape (var shape1, var (pos, _)) => $"combined shape - shape1: {shape1.Name}, pos of shape2: {pos}", | |
{ Size: (200, 200), Position: var pos } => $"shape with size 200x200 at position {pos.x}:{pos.y}", | |
Ellipse (var pos, var size) => $"Ellipse with size {size} at position {pos}", | |
Rectangle (_, var size) => $"Rectangle with size {size}", | |
_ => "another shape" | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment