Slide 9.4: An example of multiple forms (cont.)
Slide 9.6: The switch statement (cont.)
Home

The switch Statement


For multiple conditional statements, it is better to use switch statement. The data type specified in expression must match that of case values.

The following example includes the tools:
 switch ( expression ) {
   case constant-expression1: 
     statement(s);
     break;
   case constant-expression2:
   case constant-expression3:
     statement(s);
     break;
        . 
        . 
        .
   default:
     statement(s);
 }
  • One picture box

  • Four command buttons: Now, change the text of the four command buttons to “Start,” “Next,” “OK,” and “Stop.” You may also change their names following their text respectively.

The following gives the implementation of this example. The Application.Exit statement terminates execution immediately.

 private void Stop_Click( object sender, EventArgs e ) {
    Application.Exit( );
 }