Get an IEnumerator for the Array in CSharp

Description

The following code shows how to get an IEnumerator for the Array.

Example


using System;/*  w  w w . j  a  v a 2  s . c  om*/

public class SamplesArray  {

   public static void Main()  {
      String[] myArr = new String[10];
      myArr[0] = "The";
      myArr[1] = "quick";
      myArr[2] = "brown";
      myArr[3] = "fox";
      myArr[4] = "jumped";
      myArr[5] = "over";
      myArr[6] = "the";
      myArr[7] = "lazy";
      myArr[8] = "dog";

      int i = 0;
      System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator();
      while (( myEnumerator.MoveNext() ) && ( myEnumerator.Current != null )){
         Console.WriteLine( "[{0}] {1}", i++, myEnumerator.Current );
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var