In LINQ, the Repeat method or operator is useful to generate a collection with the same number as repeated times based on specified index values.
Following is the syntax of the LINQ Repeat method to generate repeated numbers based on specified index values.
C# Code
VB.NET Code
If you observe the above syntax, we defined the Repeat method with two parameters. Here, the first parameter tells the starting elements of the integer, and the second parameter is the one that tells how many times the same number is repeated in sequence.
Following is the example of the LINQ Repeat method to generate a collection that contains the same number as repeated times.
C# Code
VB.NET Code
If you observe the above example, we defined the Repeated method with a range from (100, 10), so it will take starting number as ”100” and it will generate the same number as “10” times because here we defined the second parameter as 10 so it will return the same number 10 times.
Following is the result of the LINQ Repeat method example.
This is how we can use the LINQ Repeat method to generate collection with repeated numbers based on specified length in c#, vb.net.