thenBy - Simple

Category:
LINQ
Description: This sample uses a compound orderby to sort a list of digits, first by length of their name, and then alphabetically by the name itself.
Code:
let LINQ22() =
let digits = [ "zero"; "one"; "two"; "three"; "four"; "five"; "six"; "seven"; "eight"; "nine" ]

query {
for d in digits do
sortBy d.Length
thenBy d
select d
} |> Seq.iter(fun n -> printfn "%s" n)

//sample output
// one
// six
// two
// five
// four
// nine
// zero
// eight
// seven
// three


Execution Result:
one
six
two
five
four
nine
zero
eight
seven
three

Last edited Sep 14, 2011 at 1:48 AM by ttliu2000, version 1

Comments

No comments yet.