Enums and returning primitive types

W

Wannabe

public enum Panes
{
AccountSetup,
ProgramManagement,
CampaignManagement,
ProgramAccounting,
Partners,
MemberMangement,
SysAdmin
}

Accordion1.SelectedIndex = Panes.AccountSetup;

In the example above, you have to cast Panes.AccountSetup to an int so
Accordion1.SelectedIndex will accept it. I will be using this a lot and would
like to be able to do this without having to cast it everytime I use it. Is
there a way to set up a get accessor (a generic or anything) to cast it for
me? I want to be able to still type it like an enum to keep it readable.
 
A

Anthony Jones

Wannabe said:
public enum Panes
{
AccountSetup,
ProgramManagement,
CampaignManagement,
ProgramAccounting,
Partners,
MemberMangement,
SysAdmin
}

Accordion1.SelectedIndex = Panes.AccountSetup;

In the example above, you have to cast Panes.AccountSetup to an int so
Accordion1.SelectedIndex will accept it. I will be using this a lot and would
like to be able to do this without having to cast it everytime I use it. Is
there a way to set up a get accessor (a generic or anything) to cast it for
me? I want to be able to still type it like an enum to keep it readable.


I don't have the AJAX Controls so I can't check so see is Accordion is
sealed. If not the you could inherit Accordion control like:-

class MyAccordian : Accordion
{
// Replicate constructors you need here

public new Panes SelectedIndex
{
get { return base.SelectedIndex; }
set { base.SelectedIndex = (int)value; }
}
}

personally I think thats more trouble than its worth.

Sadly you can't add other other members to an enum, it would be nice to be
able to choose to add a implicit operator int to an enum.
 
W

Wannabe

Thanks for the reply, but you are right...that was more trouble than it is
worth. I will just stay with doing it my original way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top