headOrDefault - Simple

Category:
LINQ
Description: This sample uses FirstOrDefault to try to return the first element of the sequence, unless there are no elements, in which case the default value for that type is returned.
Code:
let LINQ26() =
let numbers : int list = []
let firstNumOrDefault =
query {
for n in numbers do
headOrDefault
}
printfn "%A" firstNumOrDefault

//sample output
// 0

Execution Result:
0

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

Comments

No comments yet.