如何将弱类型ICollection转换为F#列表?

时间:2015-11-10 17:20:46

标签: c# f#

我有ICollection并需要将其转换为F#List。如果集合是强类型的,即ICollection<'T>,很明显我可以写:

let myList = List.ofSeq myCollection

但是如何使用弱类型的集合执行此操作?

1 个答案:

答案 0 :(得分:3)

let somecoll = ... // Assuming somecoll is ICollection of something
let whatever = somecoll 
               |> Seq.cast // Getting F# Seq
               |> List.ofSeq // or Array.ofSeq