Enum Values As Bit Flags

Enumerations can be designed for supporting bitwise operations by marking them with the Flags attribute. This allows combining enumeration values with bitwise operators such as OR. Consider the following implementation of the Sports enumeration that was described previously:

image

By applying the Flags attribute, the values for each enumeration value now become bitflag patterns that have a binary representation such as the following:

image

Basically combining all values with the OR operator will result in a 11111111 binary value. For ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.