Switch 语句示例 [英] Example of Switch Statements

查看:25
本文介绍了Switch 语句示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这个文本框的总和是:PostDiscountTextBox.Text = $500.00,我们如何使 Switch 语句说明如果折扣后成本金额在 0.00 和 999.99 之间,显示一个消息框,并显示消息此金额符合条件A-100"飞行常客里程"和确定"按钮?

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?

有人能提供一个 switch 语句的例子吗?

到目前为止,我只有这个,我认为它根本没有遵循任何东西.有人会指导我完成这个吗?谢谢.

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)

感谢所有提供帮助的人,但我正试图弄清楚如何使用 switch 语句来评估基于一系列数值的折扣后成本(与 if 语句无关).是的,会有很多案例,这将是我的前两个案例.有人会好心地为我提供一个例子,以便我可以填写其余的案例吗?我有很多.谢谢.

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.

如果折扣后成本金额介于 0.00 和 999.99 之间,则显示一个消息框,其中包含此金额符合 'A-100' 飞行常客里程资格"的消息.和一个确定"按钮.不应使用标题栏文本或图标.

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.

如果折扣后成本金额介于 1,000.00 和 1,499.99 之间,则显示一个消息框,其中显示此金额符合 'B-500' 飞行常客里程的条件".和一个确定"按钮.不应使用标题栏文本或图标.

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.

推荐答案

那种switch 在 C# 中不允许使用.

That kind of switch usage is not allowed in C#.

这是一个正确使用switch的例子

Here is an example of proper switch usage

switch(n)       
{         
   case 1:   
      cost += 25;
      break;                  
   case 2:            
      cost += 25;
      break;           
   case 3:            
      cost += 50;
      break;         
   default:            
      Console.WriteLine("Invalid selection. Please select 1, 2, or 3.");            
      break;      
 }

你的例子应该转换成 if-elseif-else 语句:

Your example should be transform into if-elseif-else statement:

if(first_case_predicate)
{

}
else if(another_predicate)
{

}
else
{
    // like 'default' of switch
}

这篇关于Switch 语句示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆