Export (0) Print
Expand All
Expand Minimize

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.

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

ADD
Show:
© 2014 Microsoft