• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

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?
0
scm0sml
Asked:
scm0sml
  • 2
2 Solutions
 
Bob LearnedCommented:
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 NolanCommented:
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 NolanCommented:
Yes, but the static class could also be available across your project.  It's just a matter of where it "belongs".
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now