Connecting Tech Pros Worldwide Help | Site Map

<Flags()> ENUM attibute

Chad
Guest
 
Posts: n/a
#1: Apr 26 '06
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
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#2: Apr 26 '06

re: <Flags()> ENUM attibute


"Chad" <chad.dokmanovich@unisys.com> schrieb:[color=blue]
>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?[/color]

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/>

Mattias Sjögren
Guest
 
Posts: n/a
#3: Apr 26 '06

re: <Flags()> ENUM attibute


>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(WithF lags), 3, "g"))
Console.WriteLine(System.Enum.Format(GetType(NoFla gs), 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.
Closed Thread