Linked Questions

775 votes
26 answers
1.4m views

Multiple cases in switch statement

Is there a way to fall through multiple case statements without stating case value: repeatedly? I know this works: switch (value) { case 1: case 2: case 3: // Do some stuff ...
theo's user avatar
  • 8,961
20 votes
10 answers
21k views

Switch Statement in C# [duplicate]

Does anyone know if it's possible to include a range in a switch statement (and if so, how)? For example: switch (x) { case 1: //do something break; case 2..8: //do something ...
Paul Michaels's user avatar
12 votes
7 answers
20k views

Switch case, check ranges in C# 3.5 [duplicate]

In C#, the switch statement doesn't allow cases to span ranges of values. I don't like the idea of using if-else loops for this purpose, so are there any other ways to check numeric ranges in C#?
Kenny's user avatar
  • 839
0 votes
1 answer
395 views

How to build a ranged switch case expression at runtime? [duplicate]

I am building a Switch expression to match ranges of integers at runtime. Currently I am able to compile and run the equivalent of the following using Expression.SwitchCase: switch(value) { case ...
TVOHM's user avatar
  • 2,742
-1 votes
3 answers
130 views

Converting if statements to switch but not working, where did conversion go wrong? [duplicate]

This is part of the code, it gets a line of numbers from a textfile and counts how many numbers fit in each specified range. I'm converting it from if, else if statements (which works fine) just for ...
Walter Melon's user avatar
1 vote
1 answer
107 views

Multiple numbers in one case [duplicate]

I'm looking for a switch statement code that can do this. if (value2 > 0) { button2.Visible = true; button3.Visible = false; button4.Visible = false; listBox2.Items.Add("Black&...
RMWTH's user avatar
  • 31
0 votes
0 answers
82 views

Why does my code give "Abnormal" as the result [duplicate]

I am trying to create a function that displays the Height of a person according to the user input, either short, average, or tall. If the user enters something else, displays "Abnormal" The problem ...
Amr Mohamed's user avatar
-1 votes
4 answers
2k views

Cannot implicitly convert type 'bool' to 'int'

private const decimal piece_rate_199 = 0.5M, piece_rate_399 = 0.55M, piece_rate_599 = 0.6M, piece_rate_600= 0.65M; private decimal Payrate, TotalPay, AveragePay, WorkerCount, ...
begineer112's user avatar
1 vote
2 answers
386 views

Using switch statement for ranges

I'm trying to map a certain wind speed (measured in meters per second) to the appropriate label, taken from http://www.windfinder.com/wind/windspeed.htm. For this, I'd like to use switch statements, ...
Acrotygma's user avatar
  • 2,569
-4 votes
3 answers
2k views

check condition with range in c# (without using if else statement) [closed]

The basic idea we follow is if (i > 0 && i < 100) { } else if (i > 100 && 1 < 150) { } This is the basic idea for range check.. Is there any good way to check these ...
Sivamohan Reddy's user avatar
1 vote
3 answers
256 views

Checking against a changing set of integer ranges using C#

When filling in a form, the user needs to specify an amount. This amount is then checked against approximately 4 to 6 ranges. The selected range is then saved in the database. The original amount will ...
Eli-ne's user avatar
  • 11
1 vote
3 answers
94 views

Changing code from if-statement to switch-statement in C#

I've never used switch case instead of if/else if, and I'm wondering how to use it. I would really appreciate the help! The task is to put in an amount of wind in a textbox(tbVindstyrke) and the code ...
pandapung's user avatar
1 vote
1 answer
74 views

Trying to find a function to calculate attribute changes in a game

I'm coding a game where after every year depending on results the attributes of characters change. The game is a movie business simulator and here is a example of the ugly code I have in place now: ...
petju's user avatar
  • 11