VB.NET Enum class
September 2, 2007
I use Enumerations in VB.NET a lot. I also try to make classes for just about everything — except (so far) for my enums.The realization of making a special class to house all my precious, helpful little enums in one place suddenly came to me.
Now that I’ve update my code to include my “Enums” class, it makes it a little easier to access the values anywhere after they have been set. It also makes it easier to pass around a tidy “myEnums” object rather that being forced to pass byRef each of the numerous enumerations that I’m using.
The only problem is that I still haven’t figuered out how to make the enums truly private in their class.

January 5, 2009 at 10:00 pm
Thanks for this post.
This is truly a question because of my ignorance, but I understand the beauty of having your enums all in one tiny-named class, but what do you mean by being able to pass around “a tidy ‘myEnums’ object”? I thought enums are automatically considered shared and can’t be accessed through an instance of a class.
I found this post looking for a way to be able to use my enums from within an entire huge project without having to type out MyEnums.MySpecialEnum.Whatever everytime, but I don’t have a common class that all my controls that may use it can inherit from. I was trying to determine if I could somehow make my enum class an interface instead and Implement that interface in all my classes, so I could use “MySpecialEnum.Whatever” everywhere instead of having to type “MyEnums.MySpecialEnum.Whatever”
Thanks for any advice you or anyone else out there can give me.
January 5, 2009 at 10:38 pm
I solved my own “problem”. I discovered I can just add a MyEnums.vb *file* in my project and put all the enums I want in there:
Public Enum firstEnum
this = 1
that = 2
End Enum
Public Enum secondEnum
these = 1
those = 2
End Enum
And I can access these enums anywhere within the namespace of that project through just
firstEnum.this
or
secondEnum.those