iterates two collections simultaneously : IEnumerator : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » IEnumerator »

 

iterates two collections simultaneously








    
 

using System;
using System.Collections.Generic;

public class Starter {
    public static void Main() {
        MyClass obj = new MyClass();
        foreach (int item in obj) {
            Console.Write(item);
        }
    }
}

public class MyClass {

    private int[] list1 = new int[] { 0, 2, 4, 6, 8 };
    private int[] list2 = new int[] { 1, 3, 5, 7, 9 };

    public IEnumerator<int> GetEnumerator() {
        for (int index = 0; index < 4; ++index) {
            yield return list1[index];
            yield return list2[index];
        }
    }

}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» IEnumerator