Using notation for flags

suggest change

The left-shift operator (<<) can be used in flag enum declarations to ensure that each flag has exactly one 1 in binary representation, as flags should.

This also helps to improve readability of large enums with plenty of flags in them.

[Flags]
public enum MyEnum 
{
    None  = 0,
    Flag1 = 1 << 0,
    Flag2 = 1 << 1,
    Flag3 = 1 << 2,
    Flag4 = 1 << 3,
    Flag5 = 1 << 4,
    ...
    Flag31 = 1 << 30
}

It is obvious now that MyEnum contains proper flags only and not any messy stuff like Flag30 = 1073741822 (or 111111111111111111111111111110 in binary) which is inappropriate.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Enum:
* Enum
* Using notation for flags

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script