c# - 用于对集合列表进行排序的 Lambda 表达式

标签 c# .net linq 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>  

我添加了下面的代码,但它要么返回“position”明智的,要么返回“No”明智的,但不会同时返回两者。

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

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

最佳答案

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

关于c# - 用于对集合列表进行排序的 Lambda 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53644785/

相关文章:

c# - 返回类型为 IEnumerable 而不仅仅是 List?

c# - 返回 Gridview 复选框 bool 值

c# - if (false == true) 在内部抛出异常时执行 block

c# - 具有多种参数类型的反射

c# - DelegatingHandler 解压缩 WebApi 中的传入请求

c# - 在 Repeater 中填充 DropDownList 不起作用

c# - 用于小型插件系统的简单 IoC 容器

c# - 使用 linq 时摆脱嵌套的 foreach 循环

c# - 将 LINQ-to-Entities 查询组合成单个查询

vb.net - LINQ 和静态 ObservableCollection