␡
- Iterating Collections and Creating Sub-lists
- Switching to yield Is Much More Efficient
- Mixing in a Predicate<T> Affords Maximum Flexibility
- Knowing yield's Basic Rules and Limitations
- Summary
Like this article? We recommend
Knowing yield's Basic Rules and Limitations
yield has some basic limitations. yield is not a keyword without return and break. By itself, yield can be used as a variable. YieldReturn has to be used in an iterator loop. yield cannot be used in anonymous methods, unsafe code is not allowed, and you cannot use ref or out parameters with yield. Finally, yield cannot appear in a catch block or a try block that has more than one catch block.