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
+16-19Lines changed: 16 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,24 +40,20 @@ There are numerous *errors* related to the `yield return` statement and iterator
40
40
<!-- The text in this list generates issues for Acrolinx, because they don't use contractions.
41
41
That's by design. The text closely matches the text of the compiler error / warning for SEO purposes.
42
42
-->
43
-
-[**CS1622**](#): *Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration.*
44
-
-[**CS1624**](#): *The body of 'accessor' cannot be an iterator block because 'type' is not an iterator interface type*
45
-
-[**CS1625**](#): *Cannot yield in the body of a finally clause*
46
-
-[**CS1626**](#): *Cannot yield a value in the body of a try block with a catch clause*
47
-
-[**CS1627**](#): *Expression expected after yield return*
48
-
-[**CS1629**](#): *Unsafe code may not appear in iterators*
49
-
-[**CS1631**](#): *Cannot yield a value in the body of a catch clause*
50
-
-[**CS1637**](#): *Iterators cannot have unsafe parameters or yield types*
51
-
-[**CS4013**](#): *Instance of type cannot be used inside a nested function, query expression, iterator block or async method*
52
-
-[**CS8154**](#): *The body cannot be an iterator block because it returns by reference*
53
-
-[**CS8176**](#): *Iterators cannot have by-reference locals*
54
-
-[**CS9237**](#): *'yield return' should not be used in the body of a lock statement*
55
-
-[**CS9238**](#): *Cannot use 'yield return' in an 'unsafe' block*
56
-
-[**CS9239**](#): *The `&` operator cannot be used on parameters or local variables in iterator methods.*
57
-
58
-
In addition, the compiler might produce the following *warning* related to `lock` statements and thread synchronization:
59
-
60
-
-[**CS9216**](#lock-warning): *A value of type `System.Threading.Lock` converted to a different type will use likely unintended monitor-based locking in `lock` statement.*
43
+
-[**CS1622**](#compiler-error-cs1622): *Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration.*
44
+
-[**CS1624**](#compiler-error-cs1624): *The body of 'accessor' cannot be an iterator block because 'type' is not an iterator interface type*
45
+
-[**CS1625**](#compiler-error-cs1625): *Cannot yield in the body of a finally clause*
46
+
-[**CS1626**](#compiler-error-cs1626): *Cannot yield a value in the body of a try block with a catch clause*
47
+
-[**CS1627**](#compiler-error-cs1627): *Expression expected after yield return*
48
+
-[**CS1629**](#compiler-error-cs1629): *Unsafe code may not appear in iterators*
49
+
-[**CS1631**](#compiler-error-cs1631): *Cannot yield a value in the body of a catch clause*
50
+
-[**CS1637**](#compiler-error-cs1637): *Iterators cannot have unsafe parameters or yield types*
51
+
-[**CS4013**](#compiler-error-cs4013): *Instance of type cannot be used inside a nested function, query expression, iterator block or async method*
52
+
-[**CS8154**](#compiler-error-cs8154): *The body cannot be an iterator block because it returns by reference*
53
+
-[**CS8176**](#compiler-error-cs8176): *Iterators cannot have by-reference locals*
54
+
-[**CS9237**](#new-errors): *'yield return' should not be used in the body of a lock statement*
55
+
-[**CS9238**](#new-errors): *Cannot use 'yield return' in an 'unsafe' block*
56
+
-[**CS9239**](#new-errors): *The `&` operator cannot be used on parameters or local variables in iterator methods.*
61
57
62
58
## Compiler Error CS1622
63
59
@@ -232,7 +228,7 @@ class C
232
228
}
233
229
```
234
230
235
-
# Compiler Error CS1631
231
+
##Compiler Error CS1631
236
232
237
233
Cannot yield a value in the body of a catch clause
238
234
@@ -476,6 +472,7 @@ class C
476
472
}
477
473
}
478
474
```
475
+
479
476
## New errors
480
477
481
478
-**CS9237**: *''yield return' should not be used in the body of a lock statement*
0 commit comments