2

I need to be able to creat number ranges that are 19+ digits long in sequence.

I tried using Enumerable.Range(120000003463014,50000).ToList();

Which works for smaller numbers but using the above I get an error saying it is too big for an int32 number. Is there any way to create a sequential range with large numbers (15 digits long sometimes I would even used numbers 25 digits long). Thank you in advance

P.S. my starting number for the current issue would be 128854323463014 Ending # 128854323513013

Adam Strobel
  • 63
  • 1
  • 13

2 Answers2

8

You can create your own version that accepts long instead:

public IEnumerable<long> CreateRange(long start, long count)
{
    var limit = start + count;

    while (start < limit)
    {
        yield return start;
        start++;
    }
}

Usage:

var range = CreateRange(120000003463014, 50000);
haim770
  • 48,394
  • 7
  • 105
  • 133
1

Some long extensions I like to use:

// ***
// *** Long Extensions
// ***
public static IEnumerable<long> Range(this long start, long count) => start.RangeBy(count, 1);
public static IEnumerable<long> RangeBy(this long start, long count, long by) {
    for (; count-- > 0; start += by)
        yield return start;
}
public static IEnumerable<long> To(this long start, long finish) => start.ToBy(finish, 1);
public static IEnumerable<long> ToBy(this long start, long end, long by) {
    var absBy = Math.Abs(by);
    if (start <= end)
        for (; start <= end; start += by)
            yield return start;
    else
        for (; start >= end; start -= by)
            yield return start;
}
public static IEnumerable<long> DownTo(this long start, long finish) => start.ToBy(finish, 1);
public static IEnumerable<long> DownToBy(this long start, long min, long by) => start.ToBy(min, by);
NetMage
  • 26,163
  • 3
  • 34
  • 55