0

any more efficient or shorter way to initialize a number of instance inside a List<>

List<SomeObject> contrats = new List<SomeObject>();
for (int i = 1; i <= rowCount; i++) 
     contrats.Add(new SomeObject());
  • 5
    You can do things like `Enumerable.Range(0, rowCount).Select(x => new SomeObject()).ToList()`, but it's not that much neater. One small improvement to your current approach would be `new List(rowCount)` – canton7 Jun 10 '20 at 08:53
  • 1
    Your current approach is pretty fine already – Pavel Anikhouski Jun 10 '20 at 08:55

0 Answers0