Solved

Little enum question

Posted on 2004-09-15
6
304 Views
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.
0
Comment
Question by:noulouk
[X]
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
6 Comments
 
LVL 10

Accepted Solution

by:
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.

Smg.
0
 
LVL 5

Assisted Solution

by:tomasX2
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}
      }
}
0
 
LVL 5

Assisted Solution

by:Kelmen
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.
0
Independent Software Vendors: 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!

 
LVL 9

Author Comment

by:noulouk
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.
0
 
LVL 9

Author Comment

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

Expert Comment

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

Smg.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to copy file 14 91
asp.net, radiobuttonlist, c# 3 69
c# deserialize JSON from web service using JsonConvert 9 62
How do you think this website does searches? 5 35
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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