averageBy - Projection

Category:
LINQ
Description: This sample uses Average to get the average length of the words in the array.
Code:
let LINQ37() =
let words = ["cherry"; "apple"; "blueberry"]
let averageLength =
query {
for w in words do
let wl = w.Length |> float
averageBy wl
}
printfn "The average word length is %A characters." averageLength

//sample output
// The average word length is 6.666666667 characters.

Execution Result:
The average word length is 6.666666667 characters.

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

Comments

No comments yet.