简体   繁体   中英

F# list to C# IEnumerable: most efficient method?

I'm currently working on an F# library with GUI written in C# and I would like to ask what is the best or correct way to pass an F# (generic) list to a C# code (generic IEnumerable).

I've found three ways so far:

[1; 2; 3; 4; 5;] |> List.toSeq

[1; 2; 3; 4; 5;] |> Seq.ofList 

[1; 2; 3; 4; 5;] :> seq<int>

Is there any practical difference between these three methods, please?

If you look in the F# library source code, you'll find out that they are all the same:

In terms of readability, I would probably use Seq.ofList or List.toSeq , especially if the code is a part of a larger F# pipeline, because then it makes the code a bit nicer:

someInput
|> List.map (fun x -> whatever) 
|> List.toSeq

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM