Created
June 19, 2018 15:34
-
-
Save christiannagel/24d5fbe9b19648185eefed8f81e99dd4 to your computer and use it in GitHub Desktop.
C# 8 switch expression
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 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