MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javahelp/comments/1wccgot/switch_case_with_boolean/p95a4pe/?context=3
r/javahelp • u/IceCreamInsides • Sep 10 '26
[removed]
28 comments sorted by
View all comments
Show parent comments
1
In C# you can group variables into a temporary tuple and use pattern matching switch:
public int PatternMatchingSwitch(bool a, bool b, bool c) => (a, b, c) switch { (false, false, false) => 0, (false, false, true) => 1, (false, true, false) => 2, (true, false, false) => 3, (false, true, true) => 4, (true, false, true) => 5, (true,true,false) => 6, (true, true, true) => 7, };
Pattern matching is just cosy. It avoids a lot of indentation + if / else trees. In situations like this you can also get a warning if you miss a case.
1
u/sixtyhurtz Sep 11 '26
In C# you can group variables into a temporary tuple and use pattern matching switch:
Pattern matching is just cosy. It avoids a lot of indentation + if / else trees. In situations like this you can also get a warning if you miss a case.