Home > Blockchain >  How can I write enums with inline calculation of the powers?
How can I write enums with inline calculation of the powers?

Time:06-02

I have once seen a beautifully and easy to follow enum.

It was written in such a way that one didn't have to calculate the powers by himself (1, 2, 4, 8, 16, 32, 64, 128, etc.), but instead, one could simply write like 1, 2, 3, 4, 5, etc.

The following is surely not correct, but you can get the flavor:

Public Enum eSomething 
        NotDefined = 0 ^ 2
        Max = 1 ^ 2
        Jeff = 2 ^ 2
        Lisa = 3 ^ 2
        Donald = 4 ^ 2

etc...

Does anybody know how to write it correctly?

Thank you very much!

CodePudding user response:

Does this work for you?

Public Enum eSomething
    NotDefined = CInt(2 ^ 0)
    Max = CInt(2 ^ 1)
    Jeff = CInt(2 ^ 2)
    Lisa = CInt(2 ^ 3)
    Donald = CInt(2 ^ 4)
End Enum
  • Related