score:10

Accepted answer

This can be achieved using Enumerable.Range

List<int> integerList = Enumerable.Range(MinValue, MaxValue - MinValue).ToList();

score:3

Just use the Enumerable.Range(int start, int count) method:

Generates a sequence of integral numbers within a specified range.

A simple example, using your MinValue and MaxValue variables:

List<int> integerList = Enumerable.Range(MinValue, MaxValue - MinValue).ToList();

Note that if MaxValue is less than MinValue, the count parameter will be less than zero and an ArgumentOutOfRangeException will be thrown.

score:1

You could use a collection initializer.

http://msdn.microsoft.com/en-us/library/bb384062.aspx

private List integerList = new List{MinValue, MaxValue};

score:2

Assuming MaxValue is always > MinValue,

var integerList = Enumerable.Range(MinValue, MaxValue-MinValue).ToList();

score:1

You could use Enumerable.Range

List<int> integerList = Enumerable.Range(MinValue, MaxValue - MinValue).ToList();

score:1

Try IEnumerable.Range(MinValue, MaxValue-MinValue).ToList(): MSDN


Related Articles