如何使用内联计算来编写枚举?

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

我曾经看过一个漂亮且易于理解的枚举。

这样写的,不用自己算幂(1、2、4、8、16、32、64、128等),而是可以简单地写成 1、2、3、4、5 等

下面肯定是不正确的,但是你可以体会到味道:

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

等...

有人知道怎么写吗?

非常感谢!

这对你有用吗?

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

我有这个枚举,我找到了一个方便的起点...

<Flags()> Public Enum Bits As Long
    none = 0
    B00 = 1L << 0 ' 1
    B01 = 1L << 1 ' 2
    B02 = 1L << 2 ' 4
    B03 = 1L << 3 ' 8
    B04 = 1L << 4 ' 16
    B05 = 1L << 5 ' 32
    B06 = 1L << 6 ' 64
    B07 = 1L << 7 ' 128
    B08 = 1L << 8 ' 256
    B09 = 1L << 9 ' 512
    B10 = 1L << 10 ' 1,024
    B11 = 1L << 11 ' 2,048
    B12 = 1L << 12 ' 4,096
    B13 = 1L << 13 ' 8,192
    B14 = 1L << 14 ' 16,384
    B15 = 1L << 15 ' 32,768
    B16 = 1L << 16 ' 65,536
    B17 = 1L << 17 ' 131,072
    B18 = 1L << 18 ' 262,144
    B19 = 1L << 19 ' 524,288
    B20 = 1L << 20 ' 1,048,576
    B21 = 1L << 21 ' 2,097,152
    B22 = 1L << 22 ' 4,194,304
    B23 = 1L << 23 ' 8,388,608
    B24 = 1L << 24 ' 16,777,216
    B25 = 1L << 25 ' 33,554,432
    B26 = 1L << 26 ' 67,108,864
    B27 = 1L << 27 ' 134,217,728
    B28 = 1L << 28 ' 268,435,456
    B29 = 1L << 29 ' 536,870,912
    B30 = 1L << 30 ' 1,073,741,824
    B31 = 1L << 31 ' 2,147,483,648
    B32 = 1L << 32 ' 4,294,967,296
    B33 = 1L << 33 ' 8,589,934,592
    B34 = 1L << 34 ' 17,179,869,184
    B35 = 1L << 35 ' 34,359,738,368
    B36 = 1L << 36 ' 68,719,476,736
    B37 = 1L << 37 ' 137,438,953,472
    B38 = 1L << 38 ' 274,877,906,944
    B39 = 1L << 39 ' 549,755,813,888
    B40 = 1L << 40 ' 1,099,511,627,776
    B41 = 1L << 41 ' 2,199,023,255,552
    B42 = 1L << 42 ' 4,398,046,511,104
    B43 = 1L << 43 ' 8,796,093,022,208
    B44 = 1L << 44 ' 17,592,186,044,416
    B45 = 1L << 45 ' 35,184,372,088,832
    B46 = 1L << 46 ' 70,368,744,177,664
    B47 = 1L << 47 ' 140,737,488,355,328
    B48 = 1L << 48 ' 281,474,976,710,656
    B49 = 1L << 49 ' 562,949,953,421,312
    B50 = 1L << 50 ' 1,125,899,906,842,624
    B51 = 1L << 51 ' 2,251,799,813,685,248
    B52 = 1L << 52 ' 4,503,599,627,370,496
    B53 = 1L << 53 ' 9,007,199,254,740,992
    B54 = 1L << 54 ' 18,014,398,509,481,984
    B55 = 1L << 55 ' 36,028,797,018,963,968
    B56 = 1L << 56 ' 72,057,594,037,927,936
    B57 = 1L << 57 ' 144,115,188,075,855,872
    B58 = 1L << 58 ' 288,230,376,151,711,744
    B59 = 1L << 59 ' 576,460,752,303,423,488
    B60 = 1L << 60 ' 1,152,921,504,606,846,976
    B61 = 1L << 61 ' 2,305,843,009,213,693,952
    B62 = 1L << 62 ' 4,611,686,018,427,387,904
    B63 = 1L << 63 ' -9,223,372,036,854,775,808
End Enum