Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Last active June 19, 2018 15:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
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