This project is read-only.
select - Filtered

Category:
LINQ
Description: This sample combines select and where to make a simple query that returns the text form of each digit less than 5.
Code:
let LINQ11() =    
let strings = [ "zero"; "one"; "two"; "three"; "four"; "five"; "six"; "seven"; "eight"; "nine" ]
let digits = strings
let numbers = [ 5; 4; 1; 3; 9; 8; 6; 7; 2; 0 ]

query {
for n in numbers do
where (n < 5)
select digits.[n]
} |> Seq.iter(fun n -> printfn "%s" n)

//sample output
// four
// one
// three
// two
// zero


Execution Result:
four
one
three
two
zero

Last edited Sep 15, 2011 at 3:34 PM by Jackhu, version 2

Comments

No comments yet.