PC Review


Reply
Thread Tools Rate Thread

Can I have enum of strings?

 
 
A.M-SG
Guest
Posts: n/a
 
      16th Sep 2005
Hi,

Can I have enum contain strings?

Thank you,
Alan


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      16th Sep 2005
Alan,
Afraid not. Integral types only (except char) - sbyte, byte, short, ushort,
int, uint, long and ulong.

All the Best,
Phil.

"A.M-SG" wrote:

> Hi,
>
> Can I have enum contain strings?
>
> Thank you,
> Alan
>
>
>

 
Reply With Quote
 
Fred Mellender
Guest
Posts: n/a
 
      16th Sep 2005
No. But if you name them right, you can use myenum.ToString() to get a
string value that might compare to what you want.

"A.M-SG" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Can I have enum contain strings?
>
> Thank you,
> Alan
>
>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      16th Sep 2005
Alan,

As others have mentioned, no, you can not. In this situation, what I
like to do is declare an enumeration, and then apply attributes to the
values of the enumeration (after all, they are static fields) which I
retrieve at runtime to get the information I need.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"A.M-SG" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Can I have enum contain strings?
>
> Thank you,
> Alan
>
>



 
Reply With Quote
 
apm
Guest
Posts: n/a
 
      16th Sep 2005

"Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Alan,
>
> As others have mentioned, no, you can not. In this situation, what I
> like to do is declare an enumeration, and then apply attributes to the
> values of the enumeration (after all, they are static fields) which I
> retrieve at runtime to get the information I need.


Are you thinking of somethine like:

public enum Goups
{
sCH3,
etc.
}

GroupAttributes ga = new GroupAttributes (etc.)

GroupAttributes [] gaArray = new etc.

gaArray[(int)sCH3] = ga;

In words: (1) make enum (2) use enum to refer to attributes stored in an
array
???????
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "A.M-SG" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> Can I have enum contain strings?
>>
>> Thank you,
>> Alan
>>
>>

>
>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      16th Sep 2005
apm,

No, I'm thinking something more like this:

public class MyAttribute : Attribute
{
// You can put other stuff in here.
}

public enum Goups
{
[field:MyAttribute]
sCH3
}

You can then write a generic routine that takes the enumeration value,
as well as the attribute to return, and return it. It works pretty well.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)


"apm" <(E-Mail Removed)> wrote in message
news:1QBWe.11752$nq.8126@lakeread05...
>
> "Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
>> Alan,
>>
>> As others have mentioned, no, you can not. In this situation, what I
>> like to do is declare an enumeration, and then apply attributes to the
>> values of the enumeration (after all, they are static fields) which I
>> retrieve at runtime to get the information I need.

>
> Are you thinking of somethine like:
>
> public enum Goups
> {
> sCH3,
> etc.
> }
>
> GroupAttributes ga = new GroupAttributes (etc.)
>
> GroupAttributes [] gaArray = new etc.
>
> gaArray[(int)sCH3] = ga;
>
> In words: (1) make enum (2) use enum to refer to attributes stored in an
> array
> ???????
>>
>> Hope this helps.
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - (E-Mail Removed)
>>
>> "A.M-SG" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi,
>>>
>>> Can I have enum contain strings?
>>>
>>> Thank you,
>>> Alan
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference of Enum and Enum.ToString() Leif Eirik Olsen Microsoft C# .NET 1 22nd Jun 2005 12:38 PM
Alternatives to Enum.Parse and Enum.Format ME Microsoft Dot NET 4 18th May 2005 10:07 AM
Alternatives to Enum.Parse and Enum.Format ME Microsoft Dot NET Compact Framework 4 18th May 2005 10:07 AM
Is enum type derived from Enum struct? Jerry Microsoft C# .NET 3 23rd Oct 2004 06:12 AM
Casting a value from a table to an Enum using Enum.ToObject KyleK Microsoft C# .NET 1 11th May 2004 04:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:32 PM.