Why [Enum]?

S

Scott M.

If square brackets in VB .NET are to alert the compiler that we are using a
word as an identifier that happens to be the same name as a reserved word,
as in:

Dim [Exit] As Integer

Then, why must I access the shared GetNames() method of an Enum with [Enum],
since Enum is the actual type's name and GetName() is a shared method of the
type?

-Scott
 
A

Armin Zingler

Scott M. said:
If square brackets in VB .NET are to alert the compiler that we are
using a word as an identifier that happens to be the same name as a
reserved word, as in:

Dim [Exit] As Integer

Then, why must I access the shared GetNames() method of an Enum with
[Enum], since Enum is the actual type's name and GetName() is a
shared method of the type?

You gave the question and the answer: Enum is the type's name, thus the
brackets. Otherwise it would be identified as the keyword that is there to
declare a new Enum type.



Armin
 
H

Herfried K. Wagner [MVP]

Scott M. said:
If square brackets in VB .NET are to alert the compiler that we are using
a word as an identifier that happens to be the same name as a reserved
word, as in:

Dim [Exit] As Integer

Then, why must I access the shared GetNames() method of an Enum with
[Enum], since Enum is the actual type's name and GetName() is a shared
method of the type?


'Enum' is a keyword used in 'Enum' type definition blocks. This keyword
would hide the type 'System.Enum' if it is not qualified by 'System.'. Thus
we must escape the keyword to cause the compiler to bind to the actual type
and not to the keyword.
 
S

Scott M.

Thanks for clearing that up.


Herfried K. Wagner said:
Scott M. said:
If square brackets in VB .NET are to alert the compiler that we are using
a word as an identifier that happens to be the same name as a reserved
word, as in:

Dim [Exit] As Integer

Then, why must I access the shared GetNames() method of an Enum with
[Enum], since Enum is the actual type's name and GetName() is a shared
method of the type?


'Enum' is a keyword used in 'Enum' type definition blocks. This keyword
would hide the type 'System.Enum' if it is not qualified by 'System.'.
Thus we must escape the keyword to cause the compiler to bind to the
actual type and not to the keyword.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top