convert .NET generic List to F# list

2019-03-22 13:38发布

Is there a built-in method to convert the .NET List<> into the F# list?

2条回答
别忘想泡老子
2楼-- · 2019-03-22 13:57

Given IEnumerable<T> foo you would do the following (in C#) to get an F# list<T>:

 var fsharpList = ListModule.OfSeq(foo);

ListModule refers to Microsoft.FSharp.Collections.ListModule, and is referred to as List from within F# itself.

查看更多
可以哭但决不认输i
3楼-- · 2019-03-22 14:02

Try List.ofSeq in the Microsoft.FSharp.Collections namespace.

#                     List.ofSeq : seq<'T> -> 'T list

It's not specifically for System.Collections.Generic.List<T>, but for IEnumerable<T> (seq<'T> in F#) types in general, so it should still work.

(It's also not strictly built into the F# language, but neither is List<T> built into C# or VB.NET. Those are all part of the respective standard libraries.)

查看更多
登录 后发表回答