Search This Blog

Saturday, January 10, 2009

C# Switch Statment

MSDN

The switch statement is a control statement that handles multiple selections by passing control to one of the case statements within its body. It takes the following form:

switch (expression)
{
case constant-expression:
statement
jump-statement
[default:
statement
jump-statement]
}

Where:

expression
An integral or string type expression.
statement
The embedded statement(s) to be executed if control is transferred to the case or the default.
jump-statement
A jump statement that transfers control out of the case body.
constant-expression
Control is transferred to a specific case according to the value of this expression.



Note:
C# switch does not fall through as the switch statement does in C++


switch (e.KeyCode)
{
case Keys.F5:
webBrowser1.Navigate(txtURL.Text);
break;
case Keys.Escape:
webBrowser1.Stop();
break;
default:
break;
}

1 comment:

Gary Kindel said...

BTW, I hate the HTML formatting at blogger....