Home All Groups Group Topic Archive Search About

<Flags()> ENUM attibute

Author
26 Apr 2006 8:21 PM
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

Author
26 Apr 2006 9:21 PM
Herfried K. Wagner [MVP]
"Chad" <chad.dokmanov***@unisys.com> schrieb:
>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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
26 Apr 2006 9:56 PM
Mattias Sjögren
>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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.