This project is read-only.
select - Record Types 2

Category:
LINQ
Description: This sample uses select to produce a sequence containing text representations of digits and whether their length is even or odd.
Code:
type REcord2 ={ Digit:string; Even:bool}

let LINQ10() =
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 {Digit = strings.[n]; Even = (n % 2) = 0}
} |> Seq.iter(fun r -> printfn "The digit %s is %s." r.Digit (match r.Even with |true-> "even" |_ ->"odd"))

//sample output
// The digit five is odd.
// The digit four is even.
// The digit one is odd.
// The digit three is odd.
// The digit nine is odd.
// The digit eight is even.
// The digit six is even.
// The digit seven is odd.
// The digit two is even.
// The digit zero is even.


Execution Result:
The digit five is odd.
The digit four is even.
The digit one is odd.
The digit three is odd.
The digit nine is odd.
The digit eight is even.
The digit six is even.
The digit seven is odd.
The digit two is even.
The digit zero is even.

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

Comments

No comments yet.