Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading