'Using IEnumerable.Repeat to populate a counter
I want to create an IEnumerable list using Enumerable.Repeat and would like the set the Id of the objects to the nth element of the list as per the code below. Is this possible with Enumerable.Repeat or would I need to do something different?
var stuff = Enumerable.Repeat("This is element <n>", 50);
So the resulting output from the following code ...
foreach (var s in stuff)
{
Console.WriteLine(s);
}
...would be ...
This is element 0
This is element 2
This is element 3
...
This is element 49
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
