Changes

Jump to: navigation, search

The C Sharp switch Statement

1 byte added, 15:17, 1 April 2009
no edit summary
== A switch Statement Example ==
With the above information in mind we may now construct a ''switch'' statement which provides the same functionality as our previous, and somewhat unwieldy ''if ... else if ...'' construct:
<pre>
== 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'' option simply sets the ''carManufacturer'' string to ''unknown'' if none of the case statements match the string entered by the user.

Navigation menu