Control cannot fall through from one case label

The Solution to Control cannot fall through from one case label is

You missed some breaks there:

switch (searchType)
    case "SearchBooks":
        Selenium.Type("//*[@id='SearchBooks_TextInput']", searchText);

    case "SearchAuthors":
        Selenium.Type("//*[@id='SearchAuthors_TextInput']", searchText);

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.

~ Answered on 2011-07-14 16:29:54

Most Viewed Questions: