I am new to VB.Net but have a strong background in C# so it isn't that hard to learn it. One issue I have noticed is how enums work. In C# a public enum is considered static, for example:

public class foo
{
    public enum bar
    {
        enum1,
        enum2 //etc...
    }
}

If I want to access this enum I would simply do something like:

int x = (int)foo.bar.enum1

And if I were to instantiate an object of foo, that object would not contain the base enum:

foo test = new foo();
int x = (int)test.bar.enum1; //compiler would melt down, the class object doesn't have a bar property (since its static)

In VB.Net this doesn't seem to be the case. I have 15 enums in a project I am working on and they seem to be overcrowding my properties list when they don't need to be there in the first place. What I am trying to find out is if it is possible to hide these. I tried declaring them as 'Shared' (the Vb.Net equivalent of static in C#) but this throws a compiler exception. Marking them as private/protected also does me no good, since some public properties are enum types.

Dim test As foo
test = new foo()
x = test.bar.enum1 //I dont want this to be possible!  It overcrowds the properties list and makes my co-workers get headaches looking through it
x = foo.bar.enum1 //This works, but I want this to be the only way to access the enum

Update:

I found a way to achieve what I want (though not ideal) by putting the enums outside the class - so to access them you must access them directly from the namespace. If anyone knows how to do this while still keeping them within the class let me know please!!

Member Avatar for Unhnd_Exception

You can attached this above the enums you don't want viewed in your intellisense.

Public Class Foo

   <System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
  Public Enum Foo
    none = 0
  End Enum

End Class

That will get rid of the names but the bad side is if you want to use it you will no longer have intellisense and will have to physically type it.

You can attached this above the enums you don't want viewed in your intellisense.

Public Class Foo

   <System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
  Public Enum Foo
    none = 0
  End Enum

End Class

That will get rid of the names but the bad side is if you want to use it you will no longer have intellisense and will have to physically type it.

Thanks. That attribute isn't exactly trivial to figuire out haha. Due to the 'bad side' of doing that, I will just do it the way I did in my update. Seems like VB.Net 0 C# 1 at this point :P. Thread is solved.

Member Avatar for Unhnd_Exception

You can also add a class insided the class instead of outside and access that way. At least it will be 1 unit.

I just had to move from a integer to a double to keep my vb vs c# score. A few minutes ago it was vb Integer.maxvalue c# Integer.minvalue.

You can also add a class insided the class instead of outside and access that way. At least it will be 1 unit.

I just had to move from a integer to a double to keep my vb vs c# score. A few minutes ago it was vb Integer.maxvalue c# Integer.minvalue.

Lol. I think this may belong in a different thread but what exactly do you dislike about C# compared to VB.Net? In university we used C# extensively for .Net applications, but now in the workforce my boss (an oldschool VB6er) demands we use VB.Net moving forward. I find them almost identical (they are built on the same framework) except for a few syntactical and minor differences (such as the one pointed out in this thread). Don't tell me that C# lost Integer.maxvalue points due to lack of a with statement!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.