473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Enums and returning primitive types

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.

Aug 28 '08 #1
2 1011
"Wannabe" <Wa*****@discussions.microsoft.comwrote in message
news:98**********************************@microsof t.com...
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.


--
Anthony Jones - MVP ASP/ASP.NET
Aug 28 '08 #2
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.

"Anthony Jones" wrote:
"Wannabe" <Wa*****@discussions.microsoft.comwrote in message
news:98**********************************@microsof t.com...
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.


--
Anthony Jones - MVP ASP/ASP.NET
Aug 28 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
27
by: Mark A. Gibbs | last post by:
i have been toying with the idea of making my enums smarter - ie, more in line with the rest of the language. i haven't tested it yet, but what i came up with is a template like this: template...
26
by: Kip | last post by:
Greetings everyone, Is there anyone here who could point me to a page or pdf that has a list of the sizes of all of the C primitive data types on various implementations such as SPARC, x86,...
14
by: Matt | last post by:
I want to know if "int" is a primitive type, or an object? For example, the following two approaches yield the same result. > int t1 = int.Parse(TextBox2.Text); //method 1 > int t2 =...
2
by: SpotNet | last post by:
Hello CSharpies, Can Enums in C# be UInt32 Types, and not just Int32 Types. I have a lot of constant declarations that are UInt32 that I want to put in Enums to ease the use of Intellisence. I...
3
by: Josh Mcfarlane | last post by:
What's the best way to serialize and unserialize an enumeration value? Is there a defined size that an enumeration cannot exceed? For example, int size may vary based on computers, so is there...
37
by: mdh | last post by:
In one of the answers to a K&R exercise, the first couple of lines are: enum loop { NO, YES}; enum loop okloop=YES; I get the first line, but not the second. Sorry about the LOL question. ...
10
by: Noah Roberts | last post by:
I understand that different integer types might have time penalties because of word boundaries. Where can I get information clarifying this topic? A quick google didn't turn up much for me...nice...
3
by: bshumsky06 | last post by:
Hi, I am trying to parse some text into c# commands using reflection. I am new to this so there may be a simpler way of doing things. Anyhow, the below code works fine except for enums. ...
4
by: =?Utf-8?B?a2lzaG9y?= | last post by:
Hi, has any one used webservices for returning custom objects other than datasets like custom classes and their internal classes ?. What problems you have faced if any ? is there any limitation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.