<p>Is there a way to combine Enums in VB.net?</p>

[{'answer_id': 58524, 'author': 'Hath', 'author_id': 5186, 'author_profile': 'https://Stackoverflow.com/users/5186', 'pm_score': 0, 'selected': False, 'text': '<p>If you taking about using enum flags() there is a good article <a href="http://www.codeguru.com/vb/sample_chapter/article.php/c12963" rel="nofollow noreferrer" title="VB flags">here</a>.</p>\n'}, {'answer_id': 58525, 'author': 'Mendelt', 'author_id': 3320, 'author_profile': 'https://Stackoverflow.com/users/3320', 'pm_score': 1, 'selected': False, 'text': "<p>If I understand your question correctly you want to combine different enum types. So one variable can store a value from one of two different enum's right? If you're asking about storing combining two different values of one enum type you can look at Dave Arkell's explanation</p>\n\n<p>Enums are just integers with some syntactic sugar. So if you make sure there's no overlap you can combine them by casting to int.</p>\n\n<p>It won't make for pretty code though. I try to avoid using enums most of the time. Usually  if you let enums breed in your code it's just a matter of time before they give birth to repeated case statements and other messy antipatterns.</p>\n"}, {'answer_id': 58526, 'author': 'Jonas Follesø', 'author_id': 1199387, 'author_profile': 'https://Stackoverflow.com/users/1199387', 'pm_score': 1, 'selected': False, 'text': "<p>The key to combination <code>Enum</code>s is to make sure that the value is a power of two (1, 2, 4, 8, etc.) so that you can perform bit operations on them (<code>|=</code> <code>&amp;=</code>). Those <code>Enum</code>s can be be tagged with a <code>Flags</code> attribute. The <code>Anchor</code> property on Windows Forms controls is an example of such a control. If it's marked as a flag, Visual Studio will let you check values instead of selecting a single one in a drop-down in the properties designer.</p>\n"}, {'answer_id': 58527, 'author': 'Dave Arkell', 'author_id': 4002, 'author_profile': 'https://Stackoverflow.com/users/4002', 'pm_score': 7, 'selected': True, 'text': "<p>I believe what you want is a flag type enum.</p>\n<p>You need to add the Flags attribute to the top of the enum, and then you can combine enums with the 'Or' keyword.</p>\n<p>Like this:</p>\n<pre><code>&lt;Flags()&gt; _\nEnum CombinationEnums As Integer\n  HasButton = 1\n  TitleBar = 2\n  [ReadOnly] = 4\n  ETC = 8\nEnd Enum\n</code></pre>\n<p><strong>Note:</strong> 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.</p>\n<p>Combine the desired flags using the Or keyword:</p>\n<pre><code>Dim settings As CombinationEnums\nsettings = CombinationEnums.TitleBar Or CombinationEnums.Readonly\n</code></pre>\n<p>This sets TitleBar and Readonly into the enum</p>\n<p>To check what's been set:</p>\n<pre><code>If (settings And CombinationEnums.TitleBar) = CombinationEnums.TitleBar Then\n  Window.TitleBar = True\nEnd If\n</code></pre>\n"}, {'answer_id': 58535, 'author': 'Tyler', 'author_id': 5642, 'author_profile': 'https://Stackoverflow.com/users/5642', 'pm_score': 2, 'selected': False, 'text': "<p>You can use the FlagsAttribute to decorate an Enum like so which will let you combine the Enum:</p>\n\n<pre><code>&lt;FlagsAttribute&gt; _\nPublic Enumeration SecurityRights\nNone = 0\nRead = 1\nWrite = 2\nExecute = 4\n</code></pre>\n\n<p>And then call them like so (class UserPriviltes):</p>\n\n<pre><code>Public Sub New ( _\n    options As SecurityRights _\n)\n\nNew UserPrivileges(SecurityRights.Read OR SecurityRights.Execute)\n</code></pre>\n\n<p>They effectively get combined (bit math) so that the above user has both Read AND Execute all carried around in one fancy SecurityRights variable.</p>\n\n<p>To check to see if the user has a privilege you use AND (more bitwise math) to check the users enum value with the the Enum value you're checking for:</p>\n\n<pre><code>//Check to see if user has Write rights\nIf (user.Privileges And SecurityRights.Write = SecurityRigths.Write) Then\n    //Do something clever...\nElse\n    //Tell user he can't write.\nEnd If\n</code></pre>\n\n<p>HTH,\nTyler</p>\n"}]
['https://Stackoverflow.com/questions/58517', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5055/']