将.NET泛型列表转换为F#列表

时间:2022-04-11 12:56:29

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 ,但对于IEnumerable (F#中的seq <'T>)类型,所以它仍然可以工作。

(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 foo,您将执行以下操作(在C#中)以获取F#list

 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 ,但对于IEnumerable (F#中的seq <'T>)类型,所以它仍然可以工作。

(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 foo,您将执行以下操作(在C#中)以获取F#list

 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。