Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator pattern StackOverflowException #17

Open
intvalentin opened this issue Jun 4, 2021 · 0 comments
Open

Iterator pattern StackOverflowException #17

intvalentin opened this issue Jun 4, 2021 · 0 comments

Comments

@intvalentin
Copy link

For iterator pattern should be:

public IEnumerator<RadioStation> GetEnumerator()
{
            //Use can switch to this internal collection if you do not want to transform
            //return mStations.GetEnumerator();

            //use this if you want to transform the object before rendering
            foreach (var x in mStations)
            {
                yield return x;
            }
 }

IEnumerator IEnumerable.GetEnumerator()
{
            return this.GetEnumerator();
}

Currently is wrong and throws StackOverflowException.

public IEnumerator<RadioStation> GetEnumerator()
 {
            return this.GetEnumerator();
 }

 IEnumerator IEnumerable.GetEnumerator()
 {
            //Use can switch to this internal collection if you do not want to transform
            //return mStations.GetEnumerator();

            //use this if you want to transform the object before rendering
            foreach (var x in Stations)
            {
            yield return x;
            }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant