Created
January 29, 2019 17:03
-
-
Save richlander/0a2d3276a449a487421ebdd27dd5d763 to your computer and use it in GitHub Desktop.
C# 8 Switch Expression Tuple Deconstruction and Positional Pattern
This file contains 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 State ChangeState(State current, Transition transition, bool hasKey) => | |
(current, transition) switch | |
{ | |
(Opened, Close) => Closed, | |
(Closed, Open) => Opened, | |
(Closed, Lock) when hasKey => Locked, | |
(Locked, Unlock) when hasKey => Closed, | |
_ => throw new InvalidOperationException($"Invalid transition") | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment