可能重复:
使用 LINQ 对列表中每个对象的字段进行排序
我有这个收藏:
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}}
};
如何使用 LINQ 对其进行排序,以便输出为:
new sample{ id = 2, name = "sample 1", list = new List<int>{2,9}},
new sample{ id = 5, name = "sample 1", list = new List<int>{5,1,7}},
new sample{ id = 1, name = "sample 1", list = new List<int>{5,6,1}},
new sample{ id = 6, name = "sample 1", list = new List<int>{6,9,7}}
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}},
顺便说一下,这是按“列表”排序的。
谢谢