VB.Net: Combine enums
From Wiki
You can combine enums like VB does itself in more then one instance. For this to work you will have to choose powers of 2 as the value of the enum and use the Flags attribute. Something like this
- Module Module1
- Sub Main()
- CheckColor(Redcolors.Pink)
- CheckColor(Redcolors.Red)
- CheckColor(Bluecolors.Blue)
- CheckColor(Bluecolors.DarkBlue)
- CheckColor(Bluecolors.Blue Or Redcolors.Red)
- CheckColor(Purplecolors.Purple)
- Console.ReadLine()
- End Sub
- Private Sub CheckColor(ByVal color As Integer)
- If Not color = Purplecolors.Purple Then
- If Not color = Bluecolors.Blue Then
- Console.WriteLine("this is not blue or purple")
- Else
- Console.WriteLine("this is blue")
- End If
- Else
- Console.WriteLine("this is purple")
- End If
- End Sub
- <Flags()> _
- Public Enum Redcolors As Integer
- Red = 1
- Pink = 2
- End Enum
- <Flags()> _
- Public Enum Bluecolors As Integer
- Blue = 4
- DarkBlue = 8
- End Enum
- <Flags()> _
- Public Enum Purplecolors As Integer
- Purple = 5
- End Enum
- End Module


