C# enum, double previous enum value

This question already has an answer here:

  • What does the [Flags] Enum Attribute mean in C#? 10 answers

  • The reason that you need this is that the flags enum is represented as a binary number. Each value that is a power of 2 (1,2,4,8,16 etc.) corresponds to a different index in the binary number:

  • 2 -> 10
  • 4 -> 100
  • 8 -> 1000
  • This is essential so that you can determine which flags a given value actually contains. For instance if your class has an enum value of 1110 it has the flag values of 2,4 and 8.

    If you use values that are not powers of 2, c# can no longer reasonably distinguish which enum values are represented by your classes flags when performing bitwise and & .

    链接地址: http://www.djcxy.com/p/54440.html

    上一篇: 什么是[?]以上枚举/类定义?

    下一篇: C#枚举,双前一个枚举值