13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATIONvoid DoCommand(string command) {switch (command.ToLower()) {case "run":DoRun();break;case "save":DoSave();break;case "quit":DoQuit();break;default:InvalidCommand(command);break;}}end example][Note: Like the string equality operators (§14.9.7), the switch statement is case sensitive and will execute agiven switch section only if the switch expression string exactly matches a case label constant. end note]When the governing type of a switch statement is string, the value null is permitted as a case labelconstant.The statement-lists of a switch-block may contain declaration statements (§15.5). The scope of a localvariable or constant declared in a switch block is the switch block.Within a switch block, the meaning of a name used in an expression context must always be the same(§14.5.2.1).The statement list of a given switch section is reachable if the switch statement is reachable and at leastone of the following is true:• The switch expression is a non-constant value.• The switch expression is a constant value that matches a case label in the switch section.• The switch expression is a constant value that doesn’t match any case label, and the switch sectioncontains the default label.• A switch label of the switch section is referenced by a reachable goto case or goto defaultstatement.The end point of a switch statement is reachable if at least one of the following is true:• The switch statement contains a reachable break statement that exits the switch statement.• The switch statement is reachable, the switch expression is a non-constant value, and no defaultlabel is present.• The switch statement is reachable, the switch expression is a constant value that doesn’t match anycase label, and no default label is present.15.8 Iteration statementsIteration statements repeatedly execute an embedded statement.iteration-statement:while-statementdo-statementfor-statementforeach-statement15.8.1 The while statementThe while statement conditionally executes an embedded statement zero or more times.186

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!