3
我試圖弄清楚如何從C#程序集中使用F#庫,我已經使用了C#,但從未使用過F#。如何使用F#處理C#列表#
這裏是F#類..
namespace FLib
type Class1() =
member this.square(x)=x*x
member this.doit(x, op) = List.map op (Seq.toList(x))|>List.toSeq
member this.squareAllDirect(x) = List.map this.square (Seq.toList(x))|>List.toSeq
member this.squareAllIndirect(x) = this.doit x, this.square
下面是使用它的C#
class Program
{
static void Main(string[] args)
{
FLib.Class1 f = new FLib.Class1();
List<int> l=new List<int>(){1,2,3,4,5};
var q =f.squareAllDirect(l);
var r = f.squareIndirect(l);
foreach (int i in r)
Console.Write("{0},",i);
Console.ReadKey();
}
}
的squareAllDirect功能按預期工作......但是從C#中的squareAllIndirect調用有一個例外: 方法'FLib.Class1.squareAllIndirect(System.Tuple,Microsoft.FSharp.Core.FSharpFunc'2>)'的Type參數不能根據用法推斷出來。嘗試明確指定類型參數。
它說squareIndirect,而不是squareAllIndirect在你的c# –