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
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for