static Result GetResult(Morra x, Morra y) => (x, y) switch
 {
     (Morra.剪刀, Morra.布) => Result.勝,
     (Morra.布, Morra.石頭) => Result.勝,
     (Morra.石頭, Morra.剪刀) => Result.勝,
     _ when x.Equals(y) => Result.平,
     _ => Result.敗
 };
Example #2
0
     static Result GetResult(Morra first, Morra second) => (first, second) switch
     {
         (Morra.剪刀, Morra.布) => Result.勝,
         (Morra.布, Morra.石頭) => Result.勝,
         (Morra.石頭, Morra.剪刀) => Result.勝,
         // (Morra x, Morra y) when x == y => Result.平,
         // 因為是 value type 所以用 var 也可以
         //(var x, var y) when x == y => Result.平,
         // var (x, y) when x == y => Result.平,
         // 在 discard 使用 when
         _ when first == second => Result.平,
         _ => Result.敗
     };
 }