Created
November 27, 2016 07:46
-
-
Save mntone/61f8161c3882091a1e048bfc8580dee8 to your computer and use it in GitHub Desktop.
switch 文に `ValueTuple<int, int>` 以外を使って書く方法はないのだろうか?
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
| using System; | |
| namespace CSharp7Try | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| TrySwitchFeature((x: 1, y: 2)); | |
| TrySwitchFeature((x: 7, y: 2)); | |
| TrySwitchFeature((x: 1, y: -2)); | |
| TrySwitchFeature((x: -4, y: 6)); | |
| TrySwitchFeature((x: -4, y: -2)); | |
| } | |
| static void TrySwitchFeature((int x, int y) item) | |
| { | |
| switch (item) | |
| { | |
| case ValueTuple<int, int> i when i.Item1 >= 0 && i.Item2 >= 0: | |
| Console.WriteLine("x >= 0 and y >= 0"); | |
| break; | |
| case ValueTuple<int, int> i when i.Item1 >= 0: | |
| Console.WriteLine("x >= 0"); | |
| break; | |
| case ValueTuple<int, int> i when i.Item2 >= 0: | |
| Console.WriteLine("y >= 0"); | |
| break; | |
| default: | |
| Console.WriteLine("x < 0 or y < 0"); | |
| break; | |
| } | |
| } | |
| } | |
| } |
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
| x >= 0 and y >= 0 | |
| x >= 0 and y >= 0 | |
| x >= 0 | |
| y >= 0 | |
| x < 0 or y < 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment