简体   繁体   中英

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

I'm writing some F# code and I'd like to use an enum value defined in ac# 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, eg 'new Type(args)'. The required signature is: MyEnum()

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``

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM