You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/iterator-yield.md
-5Lines changed: 0 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,6 @@ f1_keywords:
13
13
- "CS4013"
14
14
- "CS8154"
15
15
- "CS8176"
16
-
- "CS9237"
17
16
- "CS9238"
18
17
- "CS9239"
19
18
helpviewer_keywords:
@@ -28,7 +27,6 @@ helpviewer_keywords:
28
27
- "CS4013"
29
28
- "CS8154"
30
29
- "CS8176"
31
-
- "CS9237"
32
30
- "CS9238"
33
31
- "CS9239"
34
32
ms.date: 07/02/2024
@@ -51,7 +49,6 @@ That's by design. The text closely matches the text of the compiler error / warn
51
49
-[**CS4013**](#ref-safety-in-iterator-methods): *Instance of type cannot be used inside a nested function, query expression, iterator block or async method*
52
50
-[**CS8154**](#structure-of-an-iterator-method): *The body cannot be an iterator block because it returns by reference*
53
51
-[**CS8176**](#ref-safety-in-iterator-methods): *Iterators cannot have by-reference locals*
54
-
-[**CS9237**](#restrictions-on-iterator-methods): *'yield return' should not be used in the body of a lock statement*
55
52
-[**CS9238**](#restrictions-on-iterator-methods): *Cannot use 'yield return' in an 'unsafe' block*
56
53
-[**CS9239**](#restrictions-on-iterator-methods): *The `&` operator cannot be used on parameters or local variables in iterator methods.*
57
54
@@ -82,15 +79,13 @@ The body of an iterator method must conform to restrictions on the `yield return
82
79
-**CS1626**: *Cannot yield a value in the body of a try block with a catch clause*
83
80
-**CS1631**: *Cannot yield a value in the body of a catch clause*
84
81
-**CS1629**: *Unsafe code may not appear in iterators*
85
-
-**CS9237**: *''yield return' should not be used in the body of a lock statement*
86
82
-**CS9238**: *Cannot use 'yield return' in an 'unsafe' block*
87
83
-**CS9239**: *The `&` operator cannot be used on parameters or local variables in iterator methods.*
88
84
89
85
These errors indicate that your code violates safety rules because an iterator returns an element and resumes to generate the next element:
90
86
91
87
- You can't `yield return` from a `catch` or `finally` clause.
92
88
- You can't `yield return` from a `try` block with a catch clause.
93
-
- You can't `yield return` from inside a `lock` statement block. Doing so can cause deadlocks.
94
89
- You can't `yield return` from an `unsafe` block. The context for an iterator creates a nested `safe` block within the enclosing `unsafe` block.
95
90
- You can't use the `&` operator to take the address of a variable in an iterator method.
0 commit comments