Implementering IEnumerable

Published 5/24/2013 by Christian in Code

Implementering IEnumerable<T> can be done as follows:

#region IEnumerable<T> Members
public IEnumerator<T> GetEnumerator()
{
    foreach (var item in List)
    {
        if (item == null)
        {
            break;
        }
        yield return item;
    }
}

IEnumerator IEnumerable.GetEnumerator()
{
    return GetEnumerator();
}
#endregion