best way to use enums

Hi,

I want to have re-usuable enums throughout my application.

Is the best way to have a static class containing the enums that I can then just use without creating a new instance of the class?
scm0smlAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
You don't need a static class, just define them outside of any class, but within the namespace block.

Example:

namespace My.Application.Example
{

    public enum ApplicationType
    {
        CSharp,
        FSharp,
        RSharp,
        PHP,
        VisualBasic,
    }
  
    public class Example
    {
    }

}

Open in new window

0
 
Bill NolanConnect With a Mentor Owner, Lead Technology ProgrammerCommented:
It completely depends on the scope you feel is appropriate.  Sometimes an enum should belong to a class (esp. a static class), sometimes to a namespace.  Etc.
0
 
scm0smlAuthor Commented:
as per the question i was looking for it to be available across my project
0
 
Bill NolanOwner, Lead Technology ProgrammerCommented:
Yes, but the static class could also be available across your project.  It's just a matter of where it "belongs".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.