switch (selection)
{
case 1 :
handleCasement ();
break ;
case 2 :
handleStandard () ;
break ;
case 3 :
handlePatio () ;
break ;
default :
Console.WriteLine ( "Invalid number" ) ;
break ;
}
The switch construction takes a value which it uses to decide which option to
perform. It executes the case which matches the value of the switch variable. Of
course this means that the type of the cases that you use must match the switch
selection value although, in true C# tradition, the compiler will give you an error if you
make a mistake. The break statement after the call of the relevant method is to stop
the program running on and performing the code which follows. In the same way as
you break out of a loop, when the break is reached the switch is finished and the
program continues running at the statement after the switch.
Another useful feature is the default option. This gives the switch somewhere to go
if the switch value doesn't match any of the cases available; in our case (sorry!) we put
out an appropriate message.