Is there an equivalent of Pythons range(12) in C#?

You're looking for the Enumerable.Range method:

var mySequence = Enumerable.Range(0, 12);

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).


Enumerable.Range(start, numElements);