Last active
June 19, 2018 15:55
-
-
Save christiannagel/9cbc2ccad32ecd75e2fed107a4b51aff to your computer and use it in GitHub Desktop.
C# 8: extended pattern matching with the switch expression - property pattern, recursive pattern
This file contains hidden or 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