Add one item multiple times to same List

You can use Repeat:

List<int> listFullOfInts = Enumerable.Repeat(42, 50).ToList();

Demo

If you already have a list and you don’t want to create a new one with ToList:

listFullOfInts.AddRange(Enumerable.Repeat(42, 50));

If you want to do add reference types without repeating the same reference, you can use Enumerable.Range+Select:

List<SomeClass> itemList = Enumerable.Range(0, 50)
    .Select(i => new SomeClass())
    .ToList();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)