fork download
  1. using static System.Console;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program {
  6. public static void Main() {
  7. var lista = CriarCompras(10);
  8. lista[0].Item = 1;
  9. foreach (var item in lista) WriteLine(item.Item);
  10. }
  11. private static List<Compra> CriarCompras(int numComprasParaGerar) {
  12. var lstCompras = new List<Compra>();
  13. lstCompras.AddRange(Enumerable.Repeat(new Compra(), numComprasParaGerar));
  14. return lstCompras;
  15. }
  16. }
  17.  
  18. public class Compra {
  19. public int Item = 0;
  20. }
  21.  
  22. //https://pt.stackoverflow.com/a/89648/101
Success #stdin #stdout 0.02s 17092KB
stdin
Standard input is empty
stdout
1
1
1
1
1
1
1
1
1
1