Two more LINQ extensions in dotnet 10

8/18/2025
1 minute read

The preview 6 of dotnet 10 brings two more functions: InfiniteSequence and Sequence.

InfiniteSequence

InfiniteSequence is a simple generator that allows you to get a sequence from a starting point via step size:

var steps = Enumerable.InfiniteSequence(0, 5)
    .Take(10)
    .ToList();

foreach (var step in steps)
{
    Console.WriteLine(step);
}

This would print 0, 5, ... 45. So be careful not to call ToList/Count and friends without Take and so on, otherwise you will be greeted by an "Out of memory" exception.

Sequence

That is almost the same as InfiniteSequence with the difference that you can define the inclusive upper bound:

var steps = Enumerable.Sequence(0, 45, 5)
    .ToList();

foreach (var step in steps)
{
    Console.WriteLine(step);
}

The result would be the same as the InfiniteSequence.

An error has occurred. This application may no longer respond until reloaded. Reload x