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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

634 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