Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C# 8 switch expression
static string M2(Shape shape)
=> shape switch
{
Shape s when s.Size.height > 100 => $"large shape with size {s.Size} at position {s.Position}",
Ellipse e => $"Ellipse with size {e.Size} at position {e.Position}",
Rectangle r => $"Rectangle with size {r.Size} at position {r.Position}",
_ => "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.