1

My input is below xml file

<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>  

I have added below code but it returns either "position" wise or "No" wise but not both.

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

sortSignalList.OrderBy(x => x.Position).OrderBy(x=>x.No).ToList();
Gauravsa
  • 6,330
  • 2
  • 21
  • 30
suraj
  • 11
  • 2
  • Possible duplicate of [LINQ OrderBy versus ThenBy](https://stackoverflow.com/questions/3760001/linq-orderby-versus-thenby) – Mick Dec 06 '18 at 04:48

3 Answers3

4
sortSignalList.OrderBy(x => x.Position).ThenBy(x=>x.No).ToList();
Xiaosu
  • 605
  • 1
  • 9
  • 21
0

Try....

sortSignalList.OrderBy(x => x.Position).ThenBy(x=>x.No).ToList()
Mick
  • 6,527
  • 4
  • 52
  • 67
0

List can also be Sorted ThenByDescending

var thenByDescResult =sortSignalList.OrderBy(s => s.Position).ThenByDescending(s => s.No);