Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Little enum question

Hi Experts,

I have an enum like this:

public enum myEnum
{
Category1Sub1 ,Category1Sub2 , Category1Sub3 , Category2Sub8 , Category2Sub24 ...
}

so I get my enum item like this: myEnum.Category1Sub1 , myEnum.Category1Sub2 , myEnum.Category2Sub8 ...

I want an enum to get enum like this: myEnum.Category1.Sub1 , myEnum.Category1.Sub2 , myEnum.Category2.Sub8 ...

Is it possible to do ?
Thanks in advance for your answers.
0
noulouk
Asked:
noulouk
3 Solutions
 
smeggheadCommented:
What you could do is create a class which contains all your sub-enums, then you could reference them like you say above.

public class MyEnum
{
    public enum Category1 {Sub1,Sub2}
    public enum Category2 {Sub1,Sub2}
}

Hope this points you in the right direction.

Smg.
0
 
tomasX2Commented:
A very similar solution would be to create a namespace instead of a class

namespace myProject
{
      namespace myEnum
      {
            public enum Category1{Sub1,Sub2}
            public enum Category2{Sub1,Sub2}
      }
}
0
 
KelmenCommented:
Don't its possible enum.enum.

However, you can try struct.enum

struct Sample
{
MyEnum Category
...
}

Why you wanna use enum.enum? Maybe telling us about your requirement, there will be a better approach on that.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
nouloukAuthor Commented:
Thanks, I think create namespaces is the best way, but I have troubles with nested namespaces.

I created a file class. Here is the code:
using System;
using System.Data;
using System.Web;
using System.ComponentModel;

namespace myNamespace.Category1
{

    namespace SubCategory1
                public class classinsub1
    {
    // code
    }
}

In my webapp, I define using namespaces like this:
using myNamespace.Category1;
The problem is that I can't reach SubCategory1 namespace: I must declare Category1.SubCategory1 .
I just want to use this SubCategory1.myfunction() instead of Category1.SubCategory1.myfunction() .

Hope you could help me.
0
 
nouloukAuthor Commented:
Sorry replace myfunction() by classinsub1
0
 
smeggheadCommented:
Then use classes rather that namespaces, or declare the namespace outside of your application's name space (myNamespace)

Smg.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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