Example of Switch Statements(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 语句示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Switch 语句示例
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01