I have an object of type IEnumerable<IEnumerable<int>>. I need to sort the ints within the inner IEnumerable<int> but I am not sure how to do this.
I attempted to convert IEnumerable<IEnumerable<int>> to List<List<int>> to make the sort easier with this code:
var sortedResults = results.ForEach(x => x.ToList());
But I receive the error “Cannot assign void to implicitly-typed variable”
I also receive the same error if I to the sorting and the conversion all at once:
var sortedResults = results.ToList().ForEach(x => x.ToList().Sort((a ,b) => a.CompareTo(b))));
What is the best way to do this?
Just use
OrderBy– since these are integers that means you can use the number itself as criteria:Above assumes you want the output to be just a
IEnumerable<IEnumerable<int>>if you need lists, useToList()were needed.