Control cannot fall through from one case label(控制不能从一个案例标签中消失)
问题描述
我正在尝试编写一个 switch 语句,该语句将根据存在的搜索文本框在搜索字段中键入搜索词.我有以下代码.但是我得到了一个控制不能从一个案例标签中落空";错误.
switch (searchType){案例SearchBooks":Selenium.Type("//*[@id='SearchBooks_TextInput']", searchText);Selenium.Click("//*[@id='SearchBooks_SearchBtn']");案例搜索作者":Selenium.Type("//*[@id='SearchAuthors_TextInput']", searchText);Selenium.Click("//*[@id='SearchAuthors_SearchBtn']");}
<块引用>
控制不能从一个案例标签(案例SearchBooks":
)转移到另一个
控制不能从一个案例标签(案例SearchAuthors":
)转移到另一个
你错过了一些休息时间:
开关(搜索类型){案例搜索书":Selenium.Type("//*[@id='SearchBooks_TextInput']", searchText);Selenium.Click("//*[@id='SearchBooks_SearchBtn']");休息;案例搜索作者":Selenium.Type("//*[@id='SearchAuthors_TextInput']", searchText);Selenium.Click("//*[@id='SearchAuthors_SearchBtn']");休息;}
没有它们,编译器会认为您正在尝试在 case "SearchBooks":
下的行执行后立即执行 case "SearchAuthors":
下的行,这在 C# 中是不允许的.
通过在每个 case 的末尾添加 break
语句,程序在完成后退出每个 case,无论 searchType
的值是什么.
I am trying to write a switch statement that would type the search term in the search field depending on whichever search textbox is present. I have the following code. But I am getting a "Control cannot fall through from one case label" error.
switch (searchType)
{
case "SearchBooks":
Selenium.Type("//*[@id='SearchBooks_TextInput']", searchText);
Selenium.Click("//*[@id='SearchBooks_SearchBtn']");
case "SearchAuthors":
Selenium.Type("//*[@id='SearchAuthors_TextInput']", searchText);
Selenium.Click("//*[@id='SearchAuthors_SearchBtn']");
}
Control cannot fall through from one case label (
case "SearchBooks":
) to anotherControl cannot fall through from one case label (
case "SearchAuthors":
) to another
You missed some breaks there:
switch (searchType)
{
case "SearchBooks":
Selenium.Type("//*[@id='SearchBooks_TextInput']", searchText);
Selenium.Click("//*[@id='SearchBooks_SearchBtn']");
break;
case "SearchAuthors":
Selenium.Type("//*[@id='SearchAuthors_TextInput']", searchText);
Selenium.Click("//*[@id='SearchAuthors_SearchBtn']");
break;
}
Without them, the compiler thinks you're trying to execute the lines below case "SearchAuthors":
immediately after the lines under case "SearchBooks":
have been executed, which isn't allowed in C#.
By adding the break
statements at the end of each case, the program exits each case after it's done, for whichever value of searchType
.
这篇关于控制不能从一个案例标签中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:控制不能从一个案例标签中消失


基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01