For example, I have a list
var list = new List<int> { 1, 2, 3 };
and I want to repeat its content 3 times to get in result
{ 1, 2, 3, 1, 2, 3, 1, 2, 3 }
Is there a smarter/shorter solution than just AddRange
m times in for loop?
using Enumerable.Repeat
var repeatCount = 3; //change this value to repeat n times
var list = new List<int> { 1, 2, 3 };
var result = Enumerable.Repeat(list, repeatCount).SelectMany(x => x).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With