13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATIONIEnumerator enumerator =((System.IEnumerable)(collection)).GetEnumerator();try {while (enumerator.MoveNext()) {ElementType element = (ElementType)enumerator.Current;statement;}}finally {IDisposable disposable = enumerator as System.IDisposable;if (disposable != null) disposable.Dispose();}In either expansion, the enumerator variable is a temporary variable that is inaccessible in, and invisibleto, the embedded statement, and the element variable is read-only in the embedded statement.[Example: The following example prints out each value in a two-dimensional array, in element order:using System;class Test{static void Main() {double[,] values = {{1.2, 2.3, 3.4, 4.5},{5.6, 6.7, 7.8, 8.9}};}}foreach (double elementValue in values)Console.Write("{0} ", elementValue);Console.WriteLine();The output produced is as follows:1.2 2.3 3.4 4.5 5.6 6.7 7.8 8.9end example]15.9 Jump statementsJump statements unconditionally transfer control.jump-statement:break-statementcontinue-statementgoto-statementreturn-statementthrow-statementThe location to which a jump statement transfers control is called the target of the jump statement.When a jump statement occurs within a block, and the target of that jump statement is outside that block, thejump statement is said to exit the block. While a jump statement may transfer control out of a block, it cannever transfer control into a block.Execution of jump statements is complicated by the presence of intervening try statements. In the absenceof such try statements, a jump statement unconditionally transfers control from the jump statement to itstarget. In the presence of such intervening try statements, execution is more complex. If the jump statementexits one or more try blocks with associated finally blocks, control is initially transferred to thefinally block of the innermost try statement. When and if control reaches the end point of a finallyblock, control is transferred to the finally block of the next enclosing try statement. This process isrepeated until the finally blocks of all intervening try statements have been executed.[Example: In the example190

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

Saved successfully!

Ooh no, something went wrong!