If the total of this textbox is: PostDiscountTextBox.Text = $500.00, how do we make Switch statements stating that if the Post-discount Cost amount is between 0.00 and 999.99, display a message box with the message of "This amount qualifies for 'A-100' frequent flier miles" and an "OK" button?
Will someone provide an example of a switch statement?
I only have this so far, and I don't think it follows anything at all. Will someone guide me through this? Thank you.
switch (PostDiscountCostTextBox.Text)
{
case (0.00 < && PostDiscountCostTextBox.Text <= 999.00)
Thank everyone who helped, but I am trying to figure out how to use a switch statement that evaluates Post-discount Cost based on a range of numeric values (nothing about an if statement). Yes, many cases will be put, and these will be my first two cases. Will someone be kind enough to provide me an example so that I could fill the rest of my cases in? I have lots. Thank you.
If the Post-discount Cost amount is between 0.00 and 999.99, display a message box with the message of "This amount qualifies for 'A-100' frequent flier miles." and an "OK" button. No title bar text or icon should be used.
If the Post-discount Cost amount is between 1,000.00 and 1,499.99, display a message box with the message of "This amount qualifies for 'B-500' frequent flier miles." and an "OK" button. No title bar text or icon should be used.
The straightforward way is to use
if else
statements as the ranges check are not allowed for theswitch
operation. The another tricky way is to useDictionaries
. The below code snippet is a demonstration of what you want using the second approach.Not so easy as the
if else
approach, but desreves a test.That kind of
switch
usage is not allowed in C#.Here is an example of proper
switch
usageYour example should be transform into
if-elseif-else
statement:You cannot check for ranges in
switch
, you should use a chain ofelse if
. See Is using decimal ranges in a switch impossible in C#?