Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use names as enum that are already used by vb.net as keyword

I am implementing the show-message extension found on this blog: http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/

the programmer makes clever reuse of his enum to build css attribuuts but in vb.net i run on something strange.

I need this class

Enum Messagetype
    Succes = 1
    Error = 2
    Notification = 3
End Enum

but visual studio keeps giving an error on the Error enum. Is there a prefix i can use to tell visual studio its ok to use error as enum ?

like image 910
David Avatar asked May 12 '11 19:05

David


People also ask

How do you create enumeration in VB net explain with an example?

In VB.NET, Enum is a keyword known as Enumeration. Enumeration is a user-defined data type used to define a related set of constants as a list using the keyword enum statement. It can be used with module, structure, class, and procedure. For example, month names can be grouped using Enumeration.

Can we change enum values in C#?

Enums are compiled as constant static fields, their values are compiled into you assembly, so no, it's not possible to change them. (Their constant values may even be compiled into places where you reference them.)

Can we create object of enum in C#?

It is a primitive data type, which is user-defined. Enums type can be an integer (float, int, byte, double etc.) but if you use beside int, it has to be cast. Enum is used to create numeric constants in .


1 Answers

You could wrap reserved words in [] in VB.NET (the same as the @ in C#):

Enum Messagetype
    Succes = 1
    [Error] = 2
    Notification = 3
End Enum
like image 140
Darin Dimitrov Avatar answered Oct 16 '22 06:10

Darin Dimitrov