<Flags()> ENUM attibute

  • Thread starter Thread starter Chad
  • Start date Start date
C

Chad

I've used bitwise enums before (powers of 2) and have used AND and OR operator to determine which individual flags have been set, but I have never used the <Flags()> _ attribute

What advantage does this give me?

Thankoo
 
Chad said:
I've used bitwise enums before (powers of 2) and have used AND
and OR operator to determine which individual flags have been set,
but I have never used the <Flags()> _ attribute

What advantage does this give me?

I am not sure if it's currently the case but this attribute could by used by
the properties window, for example, to provide the ability to combine flags.
 
What advantage does this give me?

Like Herfried said it's mostly a benefit for tools, but it also
changes the behavior of methods such as Enum.Format. Try this


<Flags> _
Enum WithFlags
One = 1
Two = 2
End Enum

Enum NoFlags
One = 1
Two = 2
End Enum

Class Test
Shared Sub Main()
Console.WriteLine(System.Enum.Format(GetType(WithFlags), 3, "g"))
Console.WriteLine(System.Enum.Format(GetType(NoFlags), 3, "g"))
End Sub
End Class


Mattias
 
Back
Top