I'm getting used to JS after a few years of Node.js programming and I'm wondering how we could avoid while loops in C# to add items in an array by using a more "map-like" method (like AddRange in C# enumerables).
For example, if I want an array of 10 elements in JavaScript, each having a property that is incremented each time, I would do:
const cells = Array.from({ length:10 }, (_, i) => { 'number': i });
// gives cells = [{number: 0}, {number: 1}, ... until 9]
How to do that in C# without a while or for loop ?
int itemWantedCount = 10;
int i = 0;
while(cells.Count < itemWantedCount)
{
cells.Add(new MyObject(i++));
}
I'd like to find a method to use cells.AddRange instead, without for/while usage, if that's possible.