Call F# code from C#

前端 未结 4 1728
抹茶落季
抹茶落季 2020-12-04 07:13

I am playing around with F# and C#, and would like to call F# code from C#.

I managed to get it to work the other way around in Visual Studio by having two project

4条回答
  •  失恋的感觉
    2020-12-04 07:40

    From this link they seem to have a number of possible solutions, but the one that seemed the simplest was a comment:

    F# Code:

    type FCallback = delegate of int*int -> int;;
    type FCallback =
      delegate of int * int -> int
    
    let f3 (f:FCallback) a b = f.Invoke(a,b);;
    val f3 : FCallback -> int -> int -> int
    

    C# Code:

    int a = Module1.f3(Module1.f2, 10, 20); // method gets converted to the delegate automatically in C#
    

提交回复
热议问题