Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Enums

Tags:

.net

enums

vb.net

Is there a way to combine Enums in VB.net?

like image 681
digiguru Avatar asked Sep 12 '08 08:09

digiguru


People also ask

Can you extend enum Java?

No, we cannot extend an enum in Java. Java enums can extend java. lang. Enum class implicitly, so enum types cannot extend another class.

Can you make enums in JavaScript?

Enums are not supported in JavaScript natively. We can however create Enums using Object. freeze by creating objects containing all the enumerable properties and then freezing the object so that no new enum can be added to it.

What is enums in JS?

Enums are one of the few features TypeScript has which is not a type-level extension of JavaScript. Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a set of distinct cases.


1 Answers

I believe what you want is a flag type enum.

You need to add the Flags attribute to the top of the enum, and then you can combine enums with the 'Or' keyword.

Like this:

<Flags()> _ Enum CombinationEnums As Integer   HasButton = 1   TitleBar = 2   [ReadOnly] = 4   ETC = 8 End Enum 

Note: The numbers to the right are always twice as big (powers of 2) - this is needed to be able to separate the individual flags that have been set.

Combine the desired flags using the Or keyword:

Dim settings As CombinationEnums settings = CombinationEnums.TitleBar Or CombinationEnums.Readonly 

This sets TitleBar and Readonly into the enum

To check what's been set:

If (settings And CombinationEnums.TitleBar) = CombinationEnums.TitleBar Then   Window.TitleBar = True End If 
like image 171
Dave Arkell Avatar answered Sep 20 '22 05:09

Dave Arkell