Search code examples
c#sequencenumber-formatting

Int64 creating a number range


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


Solution

  • 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);