Control cannot fall through from one case label
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
.
C# Error: Control cannot fall through from one case label('case0:') to another
"Can you suggest me another way"
When you have { FirstName, LastName } data then you should think of a class Person { ... }
rather than a multidimensional array.
But I assume you want to practice arrays here. I don't see why you would need a switch at all, the trick is GetLength(dimension)
:
for (int i = 0; i < custNames.GetLength(0); i++)
{
for (int j = 0; j < custNames.GetLength(1); j++)
{
Console.WriteLine("Array [{0},{1}] : Value : {2}", i, j, custNames[i, j]);
}
}
Related Topics
Why Are Subjects Not Recommended in .Net Reactive Extensions
Performing Inserts and Updates with Dapper
Can You Configure Log4Net in Code Instead of Using a Config File
Display a Image in a Console Application
How to Use ASP.NET Identity 2.0 to Allow a User to Impersonate Another User
How to Specify a Generic Type in Xaml (Pre .Net 4 Framework)
Wpf Mvvm Why Use Contentcontrol + Datatemplate Views Rather Than Straight Xaml Window Views
Mongodb Gridfs with C#, How to Store Files Such as Images
What's the Difference Between Anonymous Methods (C# 2.0) and Lambda Expressions (C# 3.0)
Catch All Unhandled Exceptions in ASP.NET Web API
Should I Always Return Ienumerable<T> Instead of Ilist<T>
How to Get the Directory from a File's Full Path
C# an Established Connection Was Aborted by the Software in Your Host MAChine
ASP.NET Core API Only Returning First Result of List