A
archway
I know you cannot have string enumerations such as:
enum myStringEnum {
enumItem1 = "value 1",
enumItem2 = "value 2",
etc
}
However, I was wondering whether you had ever created something that would
mimic this? I have tried the following:
struct myStringEnum {
public const string EnumItem1 = "value 1";
public const string EnumItem2 = "value 2";
etc
}
However, the problem with this is when you wish to define properties in a
class whereby you wish to set a default value.
e.g.
private myStringEnum _myEnumProperty = myStringEnum.EnumItem1
This would throw an exception, as the value is a string, but you are
declaring it of myStringEnum type.
Basically, I would like to be able to create a way to group strings together
in a similar manner to an enumeration. Has anyone got any ideas on how to
achieve this?
Thanks in advance
enum myStringEnum {
enumItem1 = "value 1",
enumItem2 = "value 2",
etc
}
However, I was wondering whether you had ever created something that would
mimic this? I have tried the following:
struct myStringEnum {
public const string EnumItem1 = "value 1";
public const string EnumItem2 = "value 2";
etc
}
However, the problem with this is when you wish to define properties in a
class whereby you wish to set a default value.
e.g.
private myStringEnum _myEnumProperty = myStringEnum.EnumItem1
This would throw an exception, as the value is a string, but you are
declaring it of myStringEnum type.
Basically, I would like to be able to create a way to group strings together
in a similar manner to an enumeration. Has anyone got any ideas on how to
achieve this?
Thanks in advance