F#将序列转换为ICollection

F#将序列转换为ICollection,f#,F#,我有一系列的类型 let rackStatusesPrototype : RackStatus seq 现在我想把它赋给一个属性,它来自c#,是一个ICollection类型,但我有一个问题。我试过: let test : ICollection<RackStatus> = rackStatusesPrototype :> ICollection<RackStatus> let test:ICollection=rackStatusesPrototype:>IC

我有一系列的类型

let rackStatusesPrototype : RackStatus seq
现在我想把它赋给一个属性,它来自c#,是一个ICollection类型,但我有一个问题。我试过:

let test : ICollection<RackStatus> = rackStatusesPrototype :> ICollection<RackStatus>
let test:ICollection=rackStatusesPrototype:>ICollection

但它说的是不兼容的类型。我能做什么?

您能做的最简单的事情是
打开System.Linq
并在
rackStatusesPrototype
上调用
ToList()
,将其转换为C#list,后者实现ICollection

另外,F#Array实现了ICollection,因此seq的
rackStatusesPrototype |>Array.ofSeq
也应该可以工作。如果您与C#world没有其他交互,这可能是首选方式


请注意,F#list/set/map目前没有实现ICollection接口,但是。

您可以做的最简单的事情是
打开System.Linq
并在
rackStatusesPrototype
上调用
ToList()
,将其转换为实现ICollection的C#list

另外,F#Array实现了ICollection,因此seq的
rackStatusesPrototype |>Array.ofSeq
也应该可以工作。如果您与C#world没有其他交互,这可能是首选方式


请注意,F#list/set/map当前没有实现ICollection接口,但是。

您需要
ICollection
还是
ICollection
?它们不一样。旁注:序列并不意味着集合——有些序列是无限长的。您需要
ICollection
还是
ICollection
?它们不一样。旁注:一个序列并不意味着一个集合——有些序列是无限长的。
Array.ofSeq
Seq.toArray
似乎是进入IMHO
Array的方式。ofSeq
Seq.toArray
似乎是进入IMHO的方式