How to Convert FSharpList back to List in c#?

泄露秘密 提交于 2019-12-10 14:58:45

问题


I have an F# library that returns an FSharpList to my C# caller.

I would now like my C# caller's code to convert this into a List.

What is the most efficient way to do this in C#?

Thanks.


回答1:


Easier than I thouglt...

Starting with:

List<double> niceList= new List<double>();

From List to FSharpList I did this:

FSharpList<double> niceSharpList = ListModule.OfSeq(niceList);

and to convert back from FSharpList to List I did:

List<double> niceList= niceSharpList.ToList();



回答2:


To make this work it is essential to add references to the project core F # 4.0

For example in F# you have this

/// A list with 3 integers
let listA = [ 1; 2; 3 ]     

you can use in C# in very simply way

List<Int32> listCSHARP = Module1.listA.ToList();

foreach (Int32 i in listCSHARP)
{
     MessageBox.Show(i.ToString());
}


来源:https://stackoverflow.com/questions/18562007/how-to-convert-fsharplist-back-to-list-in-c

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