Sort Multiple Column using Orderby and ThenBy LINQ

  1. List<Student> students = new List<Student()     
  2.  {     
  3.       new Student(2, "John", 485),     
  4.       new Student(2, "Anitha", 485),     
  5.       new Student(3, "Mano", 481),     
  6.       new Student(1, "Rakesh", 495)     
  7.  };      
  8.   
  9.   
  10.  Console.WriteLine("\nBefore Sort \n");      
  11.   
  12. students.ForEach(x =>   
  13. {      
  14.           Console.WriteLine($"Rank : {x.Rank} & Name :{x.Name} & Total :{x.Total} ");      
  15. });      
  16.   
  17.   
  18. students = students.OrderBy(x => x.Rank).ThenBy(y => y.Name).ToList();      
  19.   
  20. Console.WriteLine("\nAfter Sort\n");      
  21.   
  22. students.ForEach(x => {      
  23.           Console.WriteLine($"Rank : {x.Rank} & Name :{x.Name} & Total :{x.Total} ");      
  24. });