select - Transformation

Category:
LINQ
Description: This sample uses select to produce a sequence of strings representing the text version of a sequence of integers.
Code:
let LINQ08() =
let numbers = [ 5; 4; 1; 3; 9; 8; 6; 7; 2; 0 ]
let strings = [ "zero"; "one"; "two"; "three"; "four"; "five"; "six"; "seven"; "eight"; "nine" ]

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

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


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

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

Comments

No comments yet.