convert .NET generic List to F# list

橙三吉。 提交于 2019-12-21 03:08:27

问题


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


回答1:


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.)




回答2:


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.



来源:https://stackoverflow.com/questions/3105165/convert-net-generic-list-to-f-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!