是否可以使用 LINQ 对 IEnumerable 列表中的项目进行排序?
例如:
IEnumerable<sample> sam = new List<sample>()
{
new sample{ id = 1, name = "sample 1", list = new List<int>{5,6,1}},
new sample{ id = 2, name = "sample 1", list = new List<int>{2,9}},
new sample{ id = 3, name = "sample 1", list = new List<int>{8,3,7}},
new sample{ id = 4, name = "sample 1", list = new List<int>{8,4,3}},
new sample{ id = 5, name = "sample 1", list = new List<int>{5,1,7}},
new sample{ id = 6, name = "sample 1", list = new List<int>{6,9,7}}
};
上面给出的示例的预期输出将是 List 中的排序值。预期输出为:
sample{ id = 1, name = "sample 1", list = new List<int>{1,5,6}},
sample{ id = 2, name = "sample 1", list = new List<int>{2,9}},
sample{ id = 3, name = "sample 1", list = new List<int>{3,7,8},
sample{ id = 4, name = "sample 1", list = new List<int>{3,4,8}},
sample{ id = 5, name = "sample 1", list = new List<int>{1,5,7}},
sample{ id = 6, name = "sample 1", list = new List<int>{6,7,9}}
谢谢