C# switch: case not falling through to other cases limitation
- by Mike Fielden
This question is kind of an add-on to this question
In C#, a switch case cannot fall through to other cases, this causes a compilation error. In this case I am just adding some number to the month total for the selected month and each subsequent month thereafter. (simple example, not meant to be real)
switch (month)
{
case 0:
add something to month totals
case 1:
add something to month totals
case 2:
add something to month totals
default:
break;
}
Is there a logical alternative to this in C# without having to write out a ton of if statements?
if (month <= 0)
add something to month
if (month <= 1)
add something to month
if (month <= 2)
add something to month
.... etc