Trying to create an uebersimple class that implements get enumerator, but failing madly due to lack of simple / non-functioning examples out there. All I want to do is create a
In addition to the other answers if you need a little more control over how the enumerator works or if there is a requirement to customize it beyond what the underlying data structure can provide then you can use the yield
keyword.
public class AlbumList : IEnumerable
{
public IEnumerator GetEnumerator()
{
foreach (Album item in internalStorage)
{
// You could use conditional checks or other statements here for a higher
// degree of control regarding what the enumerator returns.
yield return item;
}
}
}