How do I convert a IEnumerable<IEnumerable<T>>
to a List<List<T>>
?
How about this ...
IEnumerable<IEnumerable<int>> input = ...
List<List<int>> nestedList = input.Select(i => i.ToList()).ToList();
Using combination of the List(IEnumerable) constructor and Linq:
List<List<T>> DoIt<T>(IEnumerable<IEnumerable<T>> items)
{
return new List<List<T>>(items.Select((x) => x.ToList()));
}
May be like this:
var test2 = test.ToList().ConvertAll(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