Changes

Jump to: navigation, search

The C Sharp switch Statement

601 bytes added, 20:26, 16 January 2008
Explaining the Example
When compiled and run the sample application will prompt for a car model. Once entered the response is assigned to the ''carModel'' string variable which in turn is used as the governing variable in the ''switch'' statement. As is the case with the ''Jeep'' manufacturer, case statements may be grouped together preceding a single set of statements.
The ''default'' optionsimply sets the ''carManufacturer'' string to ''unknown'' if none of the case statements match the string entered by the user. == Using the C# goto and continue statements == In the above section we used the ''break'' to exit out of the switch statement. The result of this is to move the point of program execution to the statements immediately following the ''switch'' statement. Unfortunately this presents a problem when the ''default'' statements are also required to be executed. To do so, we can replace the ''break'' statements in our example code with a ''goto default'' statement: <pre>

Navigation menu