可能是一个非常简单的问题 - 如果我有一系列对象,我在其上运行Seq.find()
以返回单个元素,那么如何在不将整个元素存储为变量的情况下访问一个属性?
例如
type MyType = { Id : int; Text : string }
let obs = [| { Id = 1; Text = "Hello" }; { Id = 2; Text = "Goodbye" } |] :> seq<MyType>
let getFirstText (array : seq<MyType>) =
array |> Seq.find(fun mt -> mt.Id = 1) |> .Text
^^^^^
getFirstText obs |> printfn "%s"
Run Code Online (Sandbox Code Playgroud)
这给出了意外的符号'.' 在表达中.
尝试Seq.find(fun mt -> mt.Id = 1).Text
给出类型约束不匹配 - 类型'' - > MyType'与第 …
在C#LINQ,是否有之间的差A.where(...)
和A.where<SomeClass>(...)
在那里A
是某种类型的合适的收集的?