implements IEnumerable : IEnumerable « System.Collections « C# / C Sharp by API






implements IEnumerable

  

using System;
using System.Collections;
using System.Collections.Generic;

public class MyColl<T> : IEnumerable<T> {
    private T[] items;
    public MyColl( T[] items ) {
        this.items = items;
    }

    public IEnumerator<T> GetEnumerator() {
        foreach( T item in items ) {
            yield return item;
        }
    }

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

}

public class Test {
    static void Main() {
        MyColl<int> integers = new MyColl<int>( new int[] {1, 2, 3, 4} );

        foreach( int n in integers ) {
            Console.WriteLine( n );
        }
    }
}



           

   
    
  








Related examples in the same category

1.IEnumerable.DescendantNodes()
2.IEnumerable.DescendantNodesAndSelf()
3.IEnumerable.DescendantsAndSelf(String tagName)
4.IEnumerable.GetEnumerator()