public class Unicorn
{
public List<int> Numbers { get; set; }
}
unicorns.Add(new Unicorn() { Numbers = {1, 2, 3} } );
unicorns.Add(new Unicorn() { Numbers = {4, 5, 6} } );
unicorns.Add(new Unicorn() { Numbers = {7, 8, 9} } );
What’s the most efficient way in c# 4 to concatenate all the lists into one list of {1, 2, 3, 4, 5, 6, 7, 8, 9 } ?
Preferably (ideally; by preference; if one had a choice) no loops and Linq-less. I tinkered around with .FindAll, but it’s not digging it.
Without measuring, the only thing in here that gives me pause from a performance perspective is the .ToList
If there are a TON of numbers, it’s possible that ToList may repeatedly re-allocate its backing array. In order to escape this behavior, you have to have some idea about how many Numbers to expect.