Now you can easily write the following state machine in C#:<p><pre><code> 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")
};</code></pre>