This project is read-only.
select - Compound

Category:
LINQ
Description: This sample uses a compound from clause to make a query that returns all pairs of numbers from both arrays such that the number from numbersA is less than the number from numbersB.
Code:
let LINQ12() =
let numbersA = [0; 2; 4; 5; 6; 8; 9]
let numbersB = [1; 3; 5; 7; 8]

query {
for a in numbersA do
for b in numbersB do
where (a < b)
select (a,b)
} |> Seq.iter(fun (n,e) -> printfn "%d is less than %d" n e)

//sample output
// 0 is less than 1
// 0 is less than 3
// 0 is less than 5
// 0 is less than 7
// 0 is less than 8
// 2 is less than 3
// 2 is less than 5
// 2 is less than 7
// 2 is less than 8
// 4 is less than 5
// 4 is less than 7
// 4 is less than 8
// 5 is less than 7
// 5 is less than 8
// 6 is less than 7
// 6 is less than 8


Execution Result:
0 is less than 1
0 is less than 3
0 is less than 5
0 is less than 7
0 is less than 8
2 is less than 3
2 is less than 5
2 is less than 7
2 is less than 8
4 is less than 5
4 is less than 7
4 is less than 8
5 is less than 7
5 is less than 8
6 is less than 7
6 is less than 8

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

Comments

No comments yet.