Can I have enum of strings?

  • Thread starter Thread starter A.M-SG
  • Start date Start date
Alan,
Afraid not. Integral types only (except char) - sbyte, byte, short, ushort,
int, uint, long and ulong.

All the Best,
Phil.
 
No. But if you name them right, you can use myenum.ToString() to get a
string value that might compare to what you want.
 
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 said:
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 address removed)

A.M-SG said:
Hi,

Can I have enum contain strings?

Thank you,
Alan
 
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 address removed)


apm said:
Nicholas Paldino said:
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 address removed)

A.M-SG said:
Hi,

Can I have enum contain strings?

Thank you,
Alan
 
Back
Top