How to use C# object from F#?

后端 未结 3 1007
温柔的废话
温柔的废话 2020-12-11 00:37

I have the following C# code.

namespace MyMath {
    public class Arith {
        public Arith() {}
        public int Add(int x, int y) {
            return         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 01:27

    With open, you can only open namespaces are modules (similarly to the C# using keyword). Namespaces are defined with the namespace keyword, and act the same in both C# and F#. However, modules are in fact just static classes, having only static members - F# just hides that from you.

    If you look at an F# code with the reflector, you'll see that your module has been compiled as a static class. For this reason you can only use static classes as modules in F#, and in your example, the class is not static, so in order to use it, you have to create an object instance - just like you'd do in C#.

提交回复
热议问题