This crops up every now and then for me: I have some C# code badly wanting the range()
function available in Python.
I am aware of using
for
Just to complement everyone's answers, I thought I should add that Enumerable.Range(0, 12);
is closer to Python 2.x's xrange(12)
because it's an enumerable.
If anyone requires specifically a list or an array:
Enumerable.Range(0, 12).ToList();
or
Enumerable.Range(0, 12).ToArray();
are closer to Python's range(12)
.