C# Language LINQ Queries Range and Repeat

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The Range and Repeat static methods on Enumerable can be used to generate simple sequences.

Range

Enumerable.Range() generates a sequence of integers given a starting value and a count.

// Generate a collection containing the numbers 1-100 ([1, 2, 3, ..., 98, 99, 100])
var range = Enumerable.Range(1,100);

Live Demo on .NET Fiddle

Repeat

Enumerable.Repeat() generates a sequence of repeating elements given an element and the number of repetitions required.

// Generate a collection containing "a", three times (["a","a","a"])
var repeatedValues = Enumerable.Repeat("a", 3);

Live Demo on .NET Fiddle



Got any C# Language Question?