ThenBy method (with objects)

Description

The ThenBy method performs a subsequent ordering of the elements in a sequence in ascending order.

Sample

This sample sort a list of Person objects by the Age and Name properties in ascending order.

var data := List<Person>{}{ ;
   Person{}{Name := "Jon Doe", Age := 40}, ;
   Person{}{Name := "Jane Doe", Age := 20}, ;
   Person{}{Name := "Joe Schmoe", Age := 30} ;
}

var result := data:OrderBy({ q => q:Age }):ThenBy({ q => q:Name })

foreach var item in result 
   Console.WriteLine(String.Format("{0} ({1})", item:Name, item:Age))
next

Output

Jane Doe (20)
Joe Schmoe (30)
Jon Doe (40)

Complete sample

using System
using System.Linq
using System.Collections.Generic

procedure Execute() as void strict

   var data := List<Person>{}{ ;
      Person{}{Name := "Jon Doe", Age := 40}, ;
      Person{}{Name := "Jane Doe", Age := 20}, ;
      Person{}{Name := "Joe Schmoe", Age := 30} ;
   }

   var result := data:OrderBy({ q => q:Age }):ThenBy({ q => q:Name })

   foreach var item in result 
      Console.WriteLine(String.Format("{0} ({1})", item:Name, item:Age))
   next
   return

class Person
   public property Name as string auto
   public property Age as int auto
end class
var data := List<Person>{}{ ;
   Person{}{Name := "Jon Doe", Age := 40}, ;
   Person{}{Name := "Jane Doe", Age := 20}, ;
   Person{}{Name := "Joe Schmoe", Age := 30} ;
}

var result := from q in data ;
              orderby q:Age, q:Name ;
              select q

foreach var item in result 
   Console.WriteLine(String.Format("{0} ({1})", item:Name, item:Age))
next

Output

Jane Doe (20)
Joe Schmoe (30)
Jon Doe (40)

Complete sample

using System
using System.Linq
using System.Collections.Generic

procedure Execute() as void strict

   var data := List<Person>{}{ ;
      Person{}{Name := "Jon Doe", Age := 40}, ;
      Person{}{Name := "Jane Doe", Age := 20}, ;
      Person{}{Name := "Joe Schmoe", Age := 30} ;
   }

   var result := from q in data ;
                 orderby q:Age, q:Name ;
                 select q

   foreach var item in result 
      Console.WriteLine(String.Format("{0} ({1})", item:Name, item:Age))
   next
   return

class Person
   public property Name as string auto
   public property Age as int auto
end class