In C# 3.0, I\'m liking this style:
// Write the numbers 1 thru 7
foreach (int index in Enumerable.Range( 1, 7 ))
{
Console.WriteLine(index);
}
I find the latter's "minimum-to-maximum" format a lot clearer than Range
's "minimum-count" style for this purpose. Also, I don't think it's really a good practice to make a change like this from the norm that is not faster, not shorter, not more familiar, and not obviously clearer.
That said, I'm not against the idea in general. If you came up to me with syntax that looked something like foreach (int x from 1 to 8)
then I'd probably agree that that would be an improvement over a for
loop. However, Enumerable.Range
is pretty clunky.