Control Cannot Fall Through from One Case Label

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



Leave a reply



Submit