Declaring an Enum that the whole project can use?

  • Thread starter Thread starter danthman
  • Start date Start date
D

danthman

I've written an enumeration object, and now I want all the web forms
and web controls in my project to be able to use it. Is this possible?
How can it be done?

Thanks,

-Dan
 
Sure. Make it public and outside of all other classes. Maybe put it in its
own file or something. Why do you think you cannot?
 
Assuming you are using 2.0 you can put the following in your App_Code folder
inside of a .cs file:

using System;

public enum NobelGases { Helium, Neon, Argon, Krypton, Xenon, Radon }



I think that technically the 'using System' is not required but it makes the
code more readable in that you know where you are and most people look for a
using section at the top of their file. Do the same with VB.NET but change
where appropriate.
 
I put the following in the default.aspx.vb file before (i.e., outside)
the class definition:

-----
Public Enum AccessModeEnum As Byte
NoAcess
SurveyAcess
FullAcess
End Enum
-----

Then I attempted to refer to it in another aspx.vb module with:

-----
If AccessModeByte = AccessModeEnum.NoAcess Then
,,,
End If
-----

And I get a squiggly line under AccessModeEnum with the error message:

"AccessEnum is not declared"

So, not to be a smart ass, but that's what makes me think I cannot :)

Thx,

-Dan
 
Back
Top