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?
Seq.ofList
orList.toSeq
would be to ask yourself "What is my code using?" If (as in this example) you have a list and you want to produce a seq/IEnumerable for other code to consume, then useList.toSeq
. If you have received a list and you want to get a seq for your own code to consume, useSeq.ofList
. In other words, pick the function that most matches the "direction" of data flow in this particular part of your code. – Naima