在C#3.0中,我喜欢这种风格:
// Write the numbers 1 thru 7
foreach (int index in Enumerable.Range( 1, 7 ))
{
Console.WriteLine(index);
}
在传统的for
循环中:
// Write the numbers 1 thru 7
for (int index = 1; index <= 7; index++)
{
Console.WriteLine( index );
}
假设‘n’很小,那么性能不是问题,有没有人反对新风格而不是传统风格?