循环

int n = 0;
while (n < 5) 
{
    Console.WriteLine(n);
    n++;
}

输出:

0
1
2
3
4

可以使用 while 循环迭代 IEnumerators:

// Call a custom method that takes a count, and returns an IEnumerator for a list
// of strings with the names of theh largest city metro areas.
IEnumerator<string> largestMetroAreas = GetLargestMetroAreas(4);

while (largestMetroAreas.MoveNext())
{
    Console.WriteLine(largestMetroAreas.Current);
}

样本输出:

东京/横滨
纽约地铁
圣保罗
首尔/仁川