Is there a built-in method to convert the .NET List<> into the F# list?
是否有内置方法将.NET List <>转换为F#列表?
2 个解决方案
#1
40
Try List.ofSeq
in the Microsoft.FSharp.Collections
namespace.
尝试Microsoft.FSharp.Collections命名空间中的List.ofSeq。
# 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.
它不是专门用于System.Collections.Generic.List
(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.)
(它也没有严格地嵌入到F#语言中,但是C#或VB.NET中都没有构建List
#2
8
Given IEnumerable<T> foo
you would do the following (in C#) to get an F# list<T>
:
给定IEnumerable
var fsharpList = ListModule.OfSeq(foo);
ListModule
refers to Microsoft.FSharp.Collections.ListModule
, and is referred to as List
from within F# itself.
ListModule是指Microsoft.FSharp.Collections.ListModule,在F#本身中称为List。
#1
40
Try List.ofSeq
in the Microsoft.FSharp.Collections
namespace.
尝试Microsoft.FSharp.Collections命名空间中的List.ofSeq。
# 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.
它不是专门用于System.Collections.Generic.List
(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.)
(它也没有严格地嵌入到F#语言中,但是C#或VB.NET中都没有构建List
#2
8
Given IEnumerable<T> foo
you would do the following (in C#) to get an F# list<T>
:
给定IEnumerable
var fsharpList = ListModule.OfSeq(foo);
ListModule
refers to Microsoft.FSharp.Collections.ListModule
, and is referred to as List
from within F# itself.
ListModule是指Microsoft.FSharp.Collections.ListModule,在F#本身中称为List。