David
David

Reputation: 4285

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 ?

Upvotes: 9

Views: 5017

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

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

Upvotes: 31

Related Questions