creating a list of consecutive integers in c#
- by Alex Bransky
If there's already a way to get a List<int> of consecutive integers without a loop in C#, I don't know what it is, so I created a method for it.
public static List<int> GetIntegerListFromRange(int start, int end) {
if (end < start) {
throw new ArgumentException("Faulty parameter(s) passed: lower bound cannot be less than upper bound.");
}
List<int> returnList = new List<int>(end - start + 1);
for(int i = start; i <= end; i++) {
returnList.Add(i);
}
return returnList;
}