本文整理汇总了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);
}
}
}