我该怎么做才能将列表从C#传递到F#? [英] What can I do to pass a list from C# to F#?
本文介绍了我该怎么做才能将列表从C#传递到F#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道f#列表与c#列表不同.为了能够将整数列表从C#应用程序传递到f#库,我需要做些什么?我希望能够在f#代码中的数据上使用模式匹配.
I know that the f# list is not the same at the c# List. What do I need to do to be able to pass a list of ints from a c# application to an f# library? I'd like to be able to use pattern matching on the data once it's in the f# code.
推荐答案
这是我最终完成此操作的方式.
Here is how I ended up doing it.
FSharp代码:
let rec FindMaxInList list =
match list with
| [x] -> x
| h::t -> max h (FindMaxInList t)
| [] -> failwith "empty list"
let rec FindMax ( array : ResizeArray<int>) =
let list = List.ofSeq(array)
FindMaxInList list
夏普c代码:
List<int> myInts = new List<int> { 5, 6, 7 };
int max = FSModule.FindMax(myInts);
这篇关于我该怎么做才能将列表从C#传递到F#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文