Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

C# LANGUAGE SPECIFICATION

1o The state of the enumerator object is changed to suspended.

2o The MoveNext method returns true to its caller, indicating that the iteration successfully advanced

3to the next value.

4When a yield break statement is encountered (§15.14):

5o If the yield break statement is within one or more try blocks, the associated finally blocks are

6executed.

7o The state of the enumerator object is changed to after.

8o The MoveNext method returns false to its caller, indicating that the iteration is complete.

9When the end of the iterator body is encountered:

10o The state of the enumerator object is changed to after.

11o The MoveNext method returns false to its caller, indicating that the iteration is complete.

12When an exception is thrown and propagated out of the iterator block:

13o Appropriate finally blocks in the iterator body will have been executed by the exception

14propagation.

15o The state of the enumerator object is changed to after.

16o The exception propagation continues to the caller of the MoveNext method.

1727.2.2 The Current property

18An enumerator object’s Current property is affected by yield return statements in the iterator block.

19When an enumerator object is in the suspended state, the value of Current is the value set by the previous

20call to MoveNext. When an enumerator object is in the before, running, or after states, the result of

21accessing Current is unspecified.

22For an iterator block with a yield type other than object, the result of accessing Current through the

23enumerator object’s IEnumerable implementation corresponds to accessing Current through the

24enumerator object’s IEnumerator<T> implementation and casting the result to object.

2527.2.3 The Dispose method

26The Dispose method is used to clean up the iteration by bringing the enumerator object to the after state.

27If the state of the enumerator object is before, invoking Dispose changes the state to after.

28If the state of the enumerator object is running, the result of invoking Dispose is unspecified.

29If the state of the enumerator object is suspended, invoking Dispose:

30o Changes the state to running.

31o Executes any finally blocks as if the last executed yield return statement were a yield break

32statement. If this causes an exception to be thrown and propagated out of the iterator body, the state

33of the enumerator object is set to after and the exception is propagated to the caller of the Dispose

34method.

35o Changes the state to after.

36If the state of the enumerator object is after, invoking Dispose has no affect.

3727.3 Enumerable objects

38When a function member returning an enumerable interface type is implemented using an iterator block,

39invoking the function member does not immediately execute the code in the iterator block. Instead, an

40enumerable object is created and returned. The enumerable object’s GetEnumerator method returns an

426

Соседние файлы в предмете Электротехника