Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call the values of a C# enum in F#

Tags:

c#

enums

f#

I'm writing some F# code and I'd like to use an enum value defined in a c# assembly.
For instance, in the c# assembly I've got this code

public enum MyEnum
{
    valueA,
    valueB,
    valueC
}

How do I call MyEnum.valueA in F#? When I just write that, the compiler shouts:

Invalid use of a type name and/or object constructor. If necessary use 'new' and apply the constructor to its arguments, e.g. 'new Type(args)'. The required signature is: MyEnum()

like image 352
pierroz Avatar asked Sep 30 '22 05:09

pierroz


1 Answers

OK... I'm sorry, I've found my problem... My C# code was actually:

public enum MyEnum
{
    @valueA,
    @valueB,
    @valueC
}

I know, it's weird, but actually it isn't really "my" c# code...

To call it in F#, I have to write:

MyEnum.``valueA``
like image 173
pierroz Avatar answered Oct 04 '22 02:10

pierroz