Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error CS1622 

Error Message

Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration.

An iterator is a special function that returns a value via the yield statement rather than the return statement. For more information, see iterators.

The following sample generates CS1622:

// CS1622.cs
// compile with: /target:library
using System.Collections;

class C : IEnumerable
   public IEnumerator GetEnumerator()
      return (IEnumerator) this;  // CS1622
      yield return this;   // OK

Community Additions

© 2015 Microsoft