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();
1

3 Answers 3

4
sortSignalList.OrderBy(x => x.Position).ThenBy(x=>x.No).ToList();
Sign up to request clarification or add additional context in comments.

Comments

0

Try....

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

Comments

0

List can also be Sorted ThenByDescending

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.