What\'s the best way to create a list with an arbitrary number of instances of the same object? i.e is there a more compact or efficient way to do the following?
<
This wouldn't be hard to implement as an iterator:
IEnumerable CreateItems (int count) where T : new() { return CreateItems(count, () => new T()); } IEnumerable CreateItems (int count, Func creator) { for (int i = 0; i < count; i++) { yield return creator(); } }