首页 > 解决方案 > 用于对集合列表进行排序的 Lambda 表达式

问题描述

我的输入低于 xml 文件

<Employees>
  <Department Position="9">
   <Employee No="7" Status="True" />
   <Employee No="6" Status="True" />
   <Employee No="8" Status="True" />
</Department>
<Department Position="4">
  <Employee No="7" Status="True" />
  <Employee No="8" Status="True" />
  <Employee No="6" Status="True" />
</Department>
</Employees>

Out put should  be  sorted  by department position  and  employee  "No"


<Employees>
 <Department Position="4">
  <Employee No="6" Status="True" />
  <Employee No="7" Status="True" />
  <Employee No="8" Status="True" />
 </Department>
 <Department Position="9">
   <Employee No="6" Status="True" />
   <Employee No="7" Status="True" />
   <Employee No="8" Status="True" />
 </Department>  

我在下面添加了代码,但它返回“位置”明智或“否”明智,但不是两者兼而有之。

var sortSignalList = new Dictionary<int, List<string>>();

sortSignalList.OrderBy(x => x.Position).OrderBy(x=>x.No).ToList();

标签: c#.netlinqlambda

解决方案


sortSignalList.OrderBy(x => x.Position).ThenBy(x=>x.No).ToList();

推荐阅读