本文整理匯總了C#中System.Array.GetEnumerator方法的典型用法代碼示例。如果您正苦於以下問題:C# Array.GetEnumerator方法的具體用法?C# Array.GetEnumerator怎麽用?C# Array.GetEnumerator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Array
的用法示例。
在下文中一共展示了Array.GetEnumerator方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
public class SamplesArray {
public static void Main() {
// Creates and initializes a new Array.
String[] myArr = new String[10];
myArr[0] = "The";
myArr[1] = "quick";
myArr[2] = "brown";
myArr[3] = "fox";
myArr[4] = "jumps";
myArr[5] = "over";
myArr[6] = "the";
myArr[7] = "lazy";
myArr[8] = "dog";
// Displays the values of the Array.
int i = 0;
System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator();
Console.WriteLine( "The Array contains the following values:" );
while (( myEnumerator.MoveNext() ) && ( myEnumerator.Current != null ))
Console.WriteLine( "[{0}] {1}", i++, myEnumerator.Current );
}
}
輸出:
The Array contains the following values: [0] The [1] quick [2] brown [3] fox [4] jumps [5] over [6] the [7] lazy [8] dog
示例2: Array.GetEnumerator()
//引入命名空間
using System;
using System.Collections;
class MainClass
{
static void Main()
{
int[] intArray = { 10, 11, 12, 13 };
IEnumerator ie = intArray.GetEnumerator();
while (ie.MoveNext() == true)
{
int i = (int)ie.Current;
Console.WriteLine("{0}", i);
}
}
}