<p>Is there a way to fall through multiple case statements without stating <code>case value:</code> repeatedly?</p>

<p>I know this works:</p>

<pre><code>switch (value)
{
   case 1:
   case 2:
   case 3:
      // Do some stuff
      break;
   case 4:
   case 5:
   case 6:
      // Do some different stuff
      break;
   default:
       // Default stuff
      break;
}
</code></pre>

<p>but I'd like to do something like this:</p>

<pre><code>switch (value)
{
   case 1,2,3:
      // Do something
      break;
   case 4,5,6:
      // Do something
      break;
   default:
      // Do the Default
      break;
}
</code></pre>

<p>Is this syntax I'm thinking of from a different language, or am I missing something?</p>

[{'answer_id': 68611, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 10, 'selected': True, 'text': "<p>There is no syntax in C++ nor C# for the second method you mentioned. </p>\n\n<p>There's nothing wrong with your first method.  If however you have very big ranges, just use a series of if statements.</p>\n"}, {'answer_id': 68620, 'author': 'Neal', 'author_id': 7071, 'author_profile': 'https://Stackoverflow.com/users/7071', 'pm_score': 6, 'selected': False, 'text': '<p>This syntax is from the Visual Basic <a href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement#Anchor_3" rel="nofollow noreferrer">Select...Case Statement</a>:</p>\n<pre class="lang-vb prettyprint-override"><code>Dim number As Integer = 8\nSelect Case number\n    Case 1 To 5\n        Debug.WriteLine(&quot;Between 1 and 5, inclusive&quot;)\n        \' The following is the only Case clause that evaluates to True.\n    Case 6, 7, 8\n        Debug.WriteLine(&quot;Between 6 and 8, inclusive&quot;)\n    Case Is &lt; 1\n        Debug.WriteLine(&quot;Equal to 9 or 10&quot;)\n    Case Else\n        Debug.WriteLine(&quot;Not between 1 and 10, inclusive&quot;)\nEnd Select\n</code></pre>\n<p>You cannot use this syntax in C#.  Instead, you must use the syntax from your first example.</p>\n'}, {'answer_id': 68829, 'author': 'Cyber Oliveira', 'author_id': 9793, 'author_profile': 'https://Stackoverflow.com/users/9793', 'pm_score': 3, 'selected': False, 'text': '<p>One lesser known facet of <strong>switch</strong> in C# is that it relies on the <strong>operator=</strong> and since it can be overriden you could have something like this:</p>\n\n<pre><code>\nstring s = foo();\n\nswitch (s) {\n  case "abc": /*...*/ break;\n  case "def": /*...*/ break;\n}\n</code></pre>\n'}, {'answer_id': 69047, 'author': 'DGentry', 'author_id': 4761, 'author_profile': 'https://Stackoverflow.com/users/4761', 'pm_score': 3, 'selected': False, 'text': "<p>gcc implements an extension to the C language to support sequential ranges:</p>\n\n<pre><code>switch (value)\n{\n   case 1...3:\n      //Do Something\n      break;\n   case 4...6:\n      //Do Something\n      break;\n   default:\n      //Do the Default\n      break;\n}\n</code></pre>\n\n<p><B>Edit</B>: Just noticed the C# tag on the question, so presumably a gcc answer doesn't help.</p>\n"}, {'answer_id': 69106, 'author': 'Allan Wind', 'author_id': 9706, 'author_profile': 'https://Stackoverflow.com/users/9706', 'pm_score': 5, 'selected': False, 'text': '<p>You can leave out the newline which gives you:</p>\n\n<pre><code>case 1: case 2: case 3:\n   break;\n</code></pre>\n\n<p>but I consider that bad style.</p>\n'}, {'answer_id': 69173, 'author': 'Dr8k', 'author_id': 6014, 'author_profile': 'https://Stackoverflow.com/users/6014', 'pm_score': 3, 'selected': False, 'text': "<p>Another option would be to use a routine. If cases 1-3 all execute the same logic then wrap that logic in a routine and call it for each case. I know this doesn't actually get rid of the case statements, but it does implement good style and keep maintenance to a minimum.....</p>\n\n<p>[Edit] Added alternate implementation to match original question...[/Edit]</p>\n\n<pre><code>switch (x)\n{\n   case 1:\n      DoSomething();\n      break;\n   case 2:\n      DoSomething();\n      break;\n   case 3:\n      DoSomething();\n      break;\n   ...\n}\n\nprivate void DoSomething()\n{\n   ...\n}\n</code></pre>\n\n<p><strong>Alt</strong></p>\n\n<pre><code>switch (x)\n{\n   case 1:\n   case 2:\n   case 3:\n      DoSomething();\n      break;\n   ...\n}\n\nprivate void DoSomething()\n{\n   ...\n}\n</code></pre>\n"}, {'answer_id': 71023, 'author': 'Luca Molteni', 'author_id': 4206, 'author_profile': 'https://Stackoverflow.com/users/4206', 'pm_score': 4, 'selected': False, 'text': '<p>.NET Framework 3.5 has got ranges:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx" rel="noreferrer">Enumerable.Range from MSDN</a></p>\n\n<p>you can use it with "contains" and the IF statement, since like someone said the SWITCH statement uses the "==" operator.</p>\n\n<p>Here an example:</p>\n\n<pre><code>int c = 2;\nif(Enumerable.Range(0,10).Contains(c))\n    DoThing();\nelse if(Enumerable.Range(11,20).Contains(c))\n    DoAnotherThing();\n</code></pre>\n\n<p>But I think we can have more fun: since you won\'t need the return values and this action doesn\'t take parameters, you can easily use actions!</p>\n\n<pre><code>public static void MySwitchWithEnumerable(int switchcase, int startNumber, int endNumber, Action action)\n{\n    if(Enumerable.Range(startNumber, endNumber).Contains(switchcase))\n        action();\n}\n</code></pre>\n\n<p>The old example with this new method:</p>\n\n<pre><code>MySwitchWithEnumerable(c, 0, 10, DoThing);\nMySwitchWithEnumerable(c, 10, 20, DoAnotherThing);\n</code></pre>\n\n<p>Since you are passing actions, not values, you should omit the parenthesis, it\'s very important. If you need function with arguments, just change the type of <code>Action</code> to <code>Action&lt;ParameterType&gt;</code>. If you need return values, use <code>Func&lt;ParameterType, ReturnType&gt;</code>.</p>\n\n<p>In C# 3.0 there is no easy <a href="http://www.haskell.org/haskellwiki/Partial_application" rel="noreferrer">Partial Application</a> to encapsulate the fact the the case parameter is the same, but you create a little helper method (a bit verbose, tho).</p>\n\n<pre><code>public static void MySwitchWithEnumerable(int startNumber, int endNumber, Action action){ \n    MySwitchWithEnumerable(3, startNumber, endNumber, action); \n}\n</code></pre>\n\n<p>Here an example of how new functional imported statement are IMHO more powerful and elegant than the old imperative one.</p>\n'}, {'answer_id': 3382204, 'author': 'Carlos Quintanilla', 'author_id': 407944, 'author_profile': 'https://Stackoverflow.com/users/407944', 'pm_score': 10, 'selected': False, 'text': '<p>I guess this has been already answered. However, I think that you can still mix both options in a syntactically better way by doing:</p>\n\n<pre><code>switch (value)\n{\n    case 1: case 2: case 3:          \n        // Do Something\n        break;\n    case 4: case 5: case 6: \n        // Do Something\n        break;\n    default:\n        // Do Something\n        break;\n}\n</code></pre>\n'}, {'answer_id': 6637962, 'author': 'scone', 'author_id': 421329, 'author_profile': 'https://Stackoverflow.com/users/421329', 'pm_score': -1, 'selected': False, 'text': "<p>For this, you would use a goto statement.  Such as:</p>\n\n<pre><code>    switch(value){\n    case 1:\n        goto case 3;\n    case 2:\n        goto case 3;\n    case 3:\n        DoCase123();\n    //This would work too, but I'm not sure if it's slower\n    case 4:\n        goto case 5;\n    case 5:\n        goto case 6;\n    case 6:\n        goto case 7;\n    case 7:\n        DoCase4567();\n    }\n</code></pre>\n"}, {'answer_id': 7345127, 'author': 'Jiří Herník', 'author_id': 905959, 'author_profile': 'https://Stackoverflow.com/users/905959', 'pm_score': 2, 'selected': False, 'text': '<p>Actually I don\'t like the GOTO command too, but it\'s in official Microsoft materials, and here are all allowed syntaxes.</p>\n<p>If the end point of the statement list of a switch section is reachable, a compile-time error occurs. This is known as the &quot;no fall through&quot; rule. The example</p>\n<pre><code>switch (i) {\ncase 0:\n   CaseZero();\n   break;\ncase 1:\n   CaseOne();\n   break;\ndefault:\n   CaseOthers();\n   break;\n}\n</code></pre>\n<p>is valid because no switch section has a reachable end point. Unlike C and C++, execution of a switch section is not permitted to &quot;fall through&quot; to the next switch section, and the example</p>\n<pre><code>switch (i) {\ncase 0:\n   CaseZero();\ncase 1:\n   CaseZeroOrOne();\ndefault:\n   CaseAny();\n}\n</code></pre>\n<p>results in a compile-time error. When execution of a switch section is to be followed by execution of another switch section, an explicit goto case or goto default statement must be used:</p>\n<pre><code>switch (i) {\ncase 0:\n   CaseZero();\n   goto case 1;\ncase 1:\n   CaseZeroOrOne();\n   goto default;\ndefault:\n   CaseAny();\n   break;\n}\n</code></pre>\n<p>Multiple labels are permitted in a switch-section. The example</p>\n<pre><code>switch (i) {\ncase 0:\n   CaseZero();\n   break;\ncase 1:\n   CaseOne();\n   break;\ncase 2:\ndefault:\n   CaseTwo();\n   break;\n}\n</code></pre>\n<p>I believe in this particular case, the GOTO can be used, and it\'s actually the only way to fallthrough.</p>\n<p><a href="https://web.archive.org/web/20150110043637/http://msdn.microsoft.com/en-us/library/aa664749(v=vs.71).aspx" rel="nofollow noreferrer">Source</a></p>\n'}, {'answer_id': 9408179, 'author': 'Darin', 'author_id': 1227621, 'author_profile': 'https://Stackoverflow.com/users/1227621', 'pm_score': 2, 'selected': False, 'text': '<p>An awful lot of work seems to have been put into finding ways to get one of C# least used syntaxes to somehow look better or work better.  Personally I find the switch statement is seldom worth using.  I would strongly suggest analyzing what data you are testing and the end results you are wanting.  </p>\n\n<p>Let us say for example you want to quickly test values in a known range to see if they are prime numbers.  You want to avoid having your code do the wasteful calculations and you can find a list of primes in the range you want online.  You could use a massive switch statement to compare each value to known prime numbers.  </p>\n\n<p>Or you could just create an array map of primes and get immediate results:</p>\n\n<pre><code>    bool[] Primes = new bool[] {\n        false, false, true, true, false, true, false,    \n        true, false, false, false, true, false, true,\n        false,false,false,true,false,true,false};\n    private void button1_Click(object sender, EventArgs e) {\n        int Value = Convert.ToInt32(textBox1.Text);\n        if ((Value &gt;= 0) &amp;&amp; (Value &lt; Primes.Length)) {\n            bool IsPrime = Primes[Value];\n            textBox2.Text = IsPrime.ToString();\n        }\n    }\n</code></pre>\n\n<p>Maybe you want to see if a character in a string is hexadecimal.  You could use an ungly and somewhat large switch statement.</p>\n\n<p>Or you could use either regular expressions to test the char or use the IndexOf function to search for the char in a string of known hexadecimal letters:</p>\n\n<pre><code>        private void textBox2_TextChanged(object sender, EventArgs e) {\n        try {\n            textBox1.Text = ("0123456789ABCDEFGabcdefg".IndexOf(textBox2.Text[0]) &gt;= 0).ToString();\n        } catch {\n        }\n    }\n</code></pre>\n\n<p>Let us say you want to do one of 3 different actions depending on a value that will be the range of 1 to 24.  I would suggest using a set of IF statements.  And if that became too complex (Or the numbers were larger such as 5 different actions depending on a value in the range of 1 to 90) then use an enum to define the actions and create an array map of the enums.  The value would then be used to index into the array map and get the enum of the action you want.  Then use either a small set of IF statements or a very simple switch statement to process the resulting enum value.</p>\n\n<p>Also, the nice thing about an array map that converts a range of values into actions is that it can be easily changed by code.  With hard wired code you can\'t easily change behaviour at runtime but with an array map it is easy.</p>\n'}, {'answer_id': 13214755, 'author': 'none', 'author_id': 1682740, 'author_profile': 'https://Stackoverflow.com/users/1682740', 'pm_score': 4, 'selected': False, 'text': "<p>The code below <em>won't</em> work:</p>\n\n<pre><code>case 1 | 3 | 5:\n// Not working do something\n</code></pre>\n\n<p>The only way to do this is:</p>\n\n<pre><code>case 1: case 2: case 3:\n// Do something\nbreak;\n</code></pre>\n\n<p>The code you are looking for works in Visual Basic where you easily can put in ranges... in the <code>none</code> option of the <code>switch</code> statement or <code>if else</code> blocks convenient, I'd suggest to, at very extreme point, make .dll with Visual Basic and import back to your C# project.</p>\n\n<p>Note: the switch equivalent in Visual Basic is <code>Select Case</code>.</p>\n"}, {'answer_id': 44848705, 'author': 'Steve Gomez', 'author_id': 3180489, 'author_profile': 'https://Stackoverflow.com/users/3180489', 'pm_score': 7, 'selected': False, 'text': '<p><strong>Original Answer for C# 7</strong></p>\n<p>In <strong>C# 7</strong> (available by default in Visual Studio 2017/.NET Framework 4.6.2), range-based switching is now possible with the <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/switch" rel="noreferrer">switch statement</a> and would help with the OP\'s problem.</p>\n<p><strong>Example:</strong></p>\n<pre><code>int i = 5;\n\nswitch (i)\n{\n    case int n when (n &gt;= 7):\n        Console.WriteLine($&quot;I am 7 or above: {n}&quot;);\n        break;\n\n    case int n when (n &gt;= 4 &amp;&amp; n &lt;= 6 ):\n        Console.WriteLine($&quot;I am between 4 and 6: {n}&quot;);\n        break;\n\n    case int n when (n &lt;= 3):\n        Console.WriteLine($&quot;I am 3 or less: {n}&quot;);\n        break;\n}\n\n// Output: I am between 4 and 6: 5\n</code></pre>\n<p><em>Notes:</em></p>\n<ul>\n<li>The parentheses <code>(</code> and <code>)</code> are not required in the <code>when</code> condition, but are used in this example to highlight the comparison(s).</li>\n<li><code>var</code> may also be used in lieu of <code>int</code>. For example: <code>case var n when n &gt;= 7:</code>.</li>\n</ul>\n<hr />\n<p><strong>Updated examples for C# 9</strong></p>\n<pre><code>switch(myValue)\n{\n    case &lt;= 0:\n        Console.WriteLine(&quot;Less than or equal to 0&quot;);\n        break;\n    case &gt; 0 and &lt;= 10:\n        Console.WriteLine(&quot;More than 0 but less than or equal to 10&quot;);\n        break;\n    default:\n        Console.WriteLine(&quot;More than 10&quot;);\n        break;\n}\n</code></pre>\n<p><em>or</em></p>\n<pre><code>var message = myValue switch\n{\n    &lt;= 0 =&gt; &quot;Less than or equal to 0&quot;,\n    &gt; 0 and &lt;= 10 =&gt; &quot;More than 0 but less than or equal to 10&quot;,\n    _ =&gt; &quot;More than 10&quot;\n};\nConsole.WriteLine(message);\n</code></pre>\n'}, {'answer_id': 49560460, 'author': 'Maxter', 'author_id': 9448877, 'author_profile': 'https://Stackoverflow.com/users/9448877', 'pm_score': 2, 'selected': False, 'text': '<p>If you have a very big amount of strings (or any other type) case all doing the same thing, I recommend the use of a string list combined with the string.Contains property.</p>\n\n<p>So if you have a big switch statement like so:</p>\n\n<pre><code>switch (stringValue)\n{\n    case "cat":\n    case "dog":\n    case "string3":\n    ...\n    case "+1000 more string": // Too many string to write a case for all!\n        // Do something;\n    case "a lonely case"\n        // Do something else;\n    .\n    .\n    .\n}\n</code></pre>\n\n<p>You might want to replace it with an <code>if</code> statement like this:</p>\n\n<pre><code>// Define all the similar "case" string in a List\nList&lt;string&gt; listString = new List&lt;string&gt;(){ "cat", "dog", "string3", "+1000 more string"};\n// Use string.Contains to find what you are looking for\nif (listString.Contains(stringValue))\n{\n    // Do something;\n}\nelse\n{\n    // Then go back to a switch statement inside the else for the remaining cases if you really need to\n}\n</code></pre>\n\n<p>This scale well for any number of string cases.</p>\n'}, {'answer_id': 53951944, 'author': 'Carter Medlin', 'author_id': 324479, 'author_profile': 'https://Stackoverflow.com/users/324479', 'pm_score': 4, 'selected': False, 'text': '<p>Here is the complete C# 7 solution...</p>\n\n<pre><code>switch (value)\n{\n   case var s when new[] { 1,2,3 }.Contains(s):\n      // Do something\n      break;\n   case var s when new[] { 4,5,6 }.Contains(s):\n      // Do something\n      break;\n   default:\n      // Do the default\n      break;\n}\n</code></pre>\n\n<p>It works with strings too...</p>\n\n<pre><code>switch (mystring)\n{\n   case var s when new[] { "Alpha","Beta","Gamma" }.Contains(s):\n      // Do something\n      break;\n...\n}\n</code></pre>\n'}, {'answer_id': 56861502, 'author': 'JeffS', 'author_id': 935140, 'author_profile': 'https://Stackoverflow.com/users/935140', 'pm_score': 1, 'selected': False, 'text': '<p>Just to add to the conversation, using .NET 4.6.2 I was also able to do the following.\nI tested the code and it did work for me.</p>\n\n<p>You can also do multiple "OR" statements, like below:</p>\n\n<pre><code>            switch (value)\n            {\n                case string a when a.Contains("text1"):\n                    // Do Something\n                    break;\n                case string b when b.Contains("text3") || b.Contains("text4") || b.Contains("text5"):\n                    // Do Something else\n                    break;\n                default:\n                    // Or do this by default\n                    break;\n            }\n</code></pre>\n\n<p>You can also check if it matches a value in an array:</p>\n\n<pre><code>            string[] statuses = { "text3", "text4", "text5"};\n\n            switch (value)\n            {\n                case string a when a.Contains("text1"):\n                    // Do Something\n                    break;\n                case string b when statuses.Contains(value):                        \n                    // Do Something else\n                    break;\n                default:\n                    // Or do this by default\n                    break;\n            }\n</code></pre>\n'}, {'answer_id': 57801972, 'author': "Luke T O'Brien", 'author_id': 2137483, 'author_profile': 'https://Stackoverflow.com/users/2137483', 'pm_score': 3, 'selected': False, 'text': '<p>In C# 7 we now have <a href="https://visualstudiomagazine.com/articles/2017/02/01/pattern-matching.aspx" rel="noreferrer"><strong>Pattern Matching</strong></a> so you can do something like:</p>\n\n<pre class="lang-cs prettyprint-override"><code>switch (age)\n{\n  case 50:\n    ageBlock = "the big five-oh";\n    break;\n  case var testAge when (new List&lt;int&gt;()\n      { 80, 81, 82, 83, 84, 85, 86, 87, 88, 89 }).Contains(testAge):\n    ageBlock = "octogenarian";\n    break;\n  case var testAge when ((testAge &gt;= 90) &amp; (testAge &lt;= 99)):\n    ageBlock = "nonagenarian";\n    break;\n  case var testAge when (testAge &gt;= 100):\n    ageBlock = "centenarian";\n    break;\n  default:\n    ageBlock = "just old";\n    break;\n}\n</code></pre>\n'}, {'answer_id': 61410938, 'author': 'Vikas Lalwani', 'author_id': 3559462, 'author_profile': 'https://Stackoverflow.com/users/3559462', 'pm_score': 2, 'selected': False, 'text': '<p>I think this one is better in C# 7 or above.</p>\n<pre><code>switch (value)\n{\n    case var s when new[] { 1,2 }.Contains(s):\n    // Do something\n     break;\n   \n    default:\n    // Do the default\n    break;\n }\n</code></pre>\n<p>You can also check Range in C# switch case: <a href="https://stackoverflow.com/questions/20147879/switch-case-can-i-use-a-range-instead-of-a-one-number">Switch case: can I use a range instead of a one number</a></p>\n<p>OR</p>\n<pre><code> int i = 3;\n\n        switch (i)\n        {\n            case int n when (n &gt;= 7):\n                Console.WriteLine($&quot;I am 7 or above: {n}&quot;);\n                break;\n\n            case int n when (n &gt;= 4 &amp;&amp; n &lt;= 6):\n                Console.WriteLine($&quot;I am between 4 and 6: {n}&quot;);\n                break;\n\n            case int n when (n &lt;= 3):\n                Console.WriteLine($&quot;I am 3 or less: {n}&quot;);\n                break;\n        }\n</code></pre>\n<p><a href="https://qawithexperts.com/article/c-sharp/switch-case-multiple-conditions-in-c/500" rel="nofollow noreferrer">Switch case multiple conditions in C#</a></p>\n<p>Or if you want to understand basics of\n<a href="https://qawithexperts.com/tutorial/c-sharp/13/c-sharp-switch-statement" rel="nofollow noreferrer">C# switch case</a></p>\n'}, {'answer_id': 65864240, 'author': 'Esset', 'author_id': 8055755, 'author_profile': 'https://Stackoverflow.com/users/8055755', 'pm_score': 5, 'selected': False, 'text': '<p>With C#9 came the Relational Pattern Matching. This allows us to do:</p>\n<pre><code>switch (value)\n{\n    case 1 or 2 or 3:\n      // Do stuff\n      break;\n    case 4 or 5 or 6:\n      // Do stuff\n      break;\n    default:\n        // Do stuff\n        break;\n}\n</code></pre>\n<p><a href="https://dotnetcoretutorials.com/2020/08/10/relational-pattern-matching-in-c-9/" rel="noreferrer">In deep tutorial of Relational Patter in C#9</a></p>\n<p><a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/patterns3" rel="noreferrer">Pattern-matching changes for C# 9.0</a></p>\n<blockquote>\n<p>Relational patterns permit the programmer to express that an input\nvalue must satisfy a relational constraint when compared to a constant\nvalue</p>\n</blockquote>\n'}, {'answer_id': 66138570, 'author': 'AWhatley', 'author_id': 1289955, 'author_profile': 'https://Stackoverflow.com/users/1289955', 'pm_score': 2, 'selected': False, 'text': '<p>You can also have conditions that are completely different</p>\n<pre><code>            bool isTrue = true;\n\n            switch (isTrue)\n            {\n                case bool ifTrue when (ex.Message.Contains(&quot;not found&quot;)):\n                case bool ifTrue when (thing.number = 123):\n                case bool ifTrue when (thing.othernumber != 456):\n                    response.respCode = 5010;\n                    break;\n                case bool ifTrue when (otherthing.text = &quot;something else&quot;):\n                    response.respCode = 5020;\n                    break;\n                default:\n                    response.respCode = 5000;\n                    break;\n            }\n</code></pre>\n'}, {'answer_id': 68091589, 'author': 'Misha Zaslavsky', 'author_id': 2667173, 'author_profile': 'https://Stackoverflow.com/users/2667173', 'pm_score': 2, 'selected': False, 'text': '<p>In C# 8.0 you can use the new <a href="https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#switch-expressions" rel="noreferrer">switch expression</a> syntax which is ideal for your case.</p>\n<pre><code>var someOutput = value switch\n{\n    &gt;= 1 and &lt;= 3 =&gt; &lt;Do some stuff&gt;,\n    &gt;= 4 and &lt;= 6 =&gt; &lt;Do some different stuff&gt;,\n    _ =&gt; &lt;Default stuff&gt;\n};\n</code></pre>\n'}, {'answer_id': 69088932, 'author': 'Abraham', 'author_id': 14487032, 'author_profile': 'https://Stackoverflow.com/users/14487032', 'pm_score': 2, 'selected': False, 'text': '<h1>A more beautiful way to handle that</h1>\n<pre><code>if ([4, 5, 6, 7].indexOf(value) &gt; -1)\n    //Do something\n</code></pre>\n<p>You can do that for multiple values with the same result</p>\n'}, {'answer_id': 70326316, 'author': 'Osama Hussain', 'author_id': 8513973, 'author_profile': 'https://Stackoverflow.com/users/8513973', 'pm_score': 0, 'selected': False, 'text': '<p>We can also use this approach to achieve Multiple cases in switch statement... You can use as many conditions as you want using this approach..</p>\n<pre><code>    int i = 209;\n    int a = 0;\n    switch (a = (i&gt;=1 &amp;&amp; i&lt;=100) ? 1 : a){    \n    case 1:\n        System.out.println (&quot;The Number is Between 1 to 100 ==&gt; &quot; + i);\n        break;\n    default:\n        switch (a = (i&gt;100 &amp;&amp; i&lt;=200) ? 2 : a) {\n            case 2:\n                System.out.println(&quot;This Number is Between 101 to 200 ==&gt; &quot; + i);\n                break;\n        \n            default:\n                switch (a = (i&gt;200 &amp;&amp; i&lt;=300) ? 3 : a) {\n                    case 3:\n                        System.out.println(&quot;This Number is Between 201 to 300 ==&gt; &quot; + i);\n                        break;\n                \n                    default:\n                        // You can make as many conditions as you want;\n                        break;\n                }\n        }\n        \n    }\n</code></pre>\n'}, {'answer_id': 74102541, 'author': 'Nic', 'author_id': 16414383, 'author_profile': 'https://Stackoverflow.com/users/16414383', 'pm_score': 0, 'selected': False, 'text': '<p>Using new version of C# I have done in this way</p>\n<pre><code>public string GetValue(string name)\n            {\n                return name switch\n                {\n                    var x when name is &quot;test1&quot; || name is &quot;test2&quot; =&gt; &quot;finch&quot;,\n                    &quot;test2&quot; =&gt; somevalue,\n                    _ =&gt; name\n                };\n            }\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/68578', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7870/']