Why [Enum]?

  • Thread starter Thread starter Scott M.
  • Start date Start date
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
 
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
 
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.
 
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.
 
Back
Top