How to convert FSharpList to a list in C #?

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

Now I would like my calling C # code to convert it to a list.

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

Thanks.

+4
source share
2 answers

Lighter than me ...

Beginning 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(); 
+8
source

To do this, you need to add links to the core of the F # 4.0 project

For example, in F # you have this

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

you can use in c # very simple.

 List<Int32> listCSHARP = Module1.listA.ToList(); foreach (Int32 i in listCSHARP) { MessageBox.Show(i.ToString()); } 
0
source

Source: https://habr.com/ru/post/1500049/


All Articles