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.
Who is Participating?
smeggheadConnect With a Mentor Commented:
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.

tomasX2Connect With a Mentor Commented:
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}
KelmenConnect With a Mentor Commented:
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.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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.
nouloukAuthor Commented:
Sorry replace myfunction() by classinsub1
Then use classes rather that namespaces, or declare the namespace outside of your application's name space (myNamespace)

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.