Is using decimal ranges in a switch impossible in C#?

Posted by phobia on Stack Overflow See other posts from Stack Overflow or by phobia
Published on 2010-05-30T01:01:04Z Indexed on 2010/05/30 1:42 UTC
Read the original article Hit count: 312

Filed under:
|
|

I'm justing starting out learning C# and I've become stuck at something very basic.

For my first "app" I thought I'd go for something simple, so I decided for a BMI calculator.

The BMI is calculated into a decimal type which I'm now trying to use in a switch statement, but aparently decimal can't be used in a switch?

What would be the C# solution for this:

            decimal bmi = calculate_bmi(h, w);

            switch (bmi) {
                case < 18.5: 
                    bmi_description = "underweight.";
                    break;
                case > 25:
                    bmi_description = "overweight";
                case > 30:
                    bmi_description = "very overweight";
                case > 40:
                    bmi_description = "extreme overweight";
                    break;
            }

© Stack Overflow or respective owner

Related posts about c#

Related posts about decimal