Skip to content

Instantly share code, notes, and snippets.

@christiannagel

christiannagel/Program.cs

Last active Jun 19, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.