shapper said:
Got it ... I have been using Enumeration always starting at 1 so I
ended up with the idea that it was start and end not start and count.
So I was completly convinced that the problem was with my DateTime
approach. Anyway it is working now:
Enumerable.Range(DateTime.UtcNow.AddYears(-70).Year,
55).OrderByDescending(i => i)
Of course, the above is a painfully clear example of overuse of LINQ.
Sorting a range of numbers by descending order, when the range is
_already_ sorted is ridiculous overhead. There's nothing the above
achieves that makes it superior to:
int year = DateTime.UtcNow.AddYears(-16),
yearLast = year - 55;
while (year > yearLast)
{
// do something
year--;
}
Even if for some reason you decided you needed the numbers represented
as an IEnumerable<int>, but didn't want them stored in some temporary
storage as you were enumerating them (an obvious contradiction with your
chosen implementation, but let's say that constraint exists just for the
sake of discussion), then something like this would make more sense:
IEnumerable<int> Range(int start, int count)
{
if (count >= 0)
{
return Enumerable.Range(start, count);
}
if (start + count + 1 > start)
{
throw new ArgumentOutOfRangeException("when count is negative,
start + count + 1 cannot be less than Int32.MinValue");
}
while (count < 0)
{
yield return start++;
count++;
}
}
Hope that helps.
Pete