Little enum question

Posted on 2004-09-15
Last Modified: 2010-04-15
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.
Question by:noulouk
LVL 10

Accepted Solution

smegghead earned 250 total points
ID: 12069875
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.


Assisted Solution

tomasX2 earned 150 total points
ID: 12070088
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}

Assisted Solution

Kelmen earned 100 total points
ID: 12072744
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.
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.


Author Comment

ID: 12073302
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.

Author Comment

ID: 12073315
Sorry replace myfunction() by classinsub1
LVL 10

Expert Comment

ID: 12073362
Then use classes rather that namespaces, or declare the namespace outside of your application's name space (myNamespace)


Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# HTTP GET method sample code 3 58
System.Security 2 27
application restarter  - for an exe that hangs 9 27
Switching Visual Studio 2015 to normal debug display 3 27
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question