since i can not have space in enum and i am trying to do something like this but seems like does not like it….
public enum EnumState
{
NewYork,
NewMexico
}
public EnumState State
{
get
{
return EnumState ;
}
set
{
if (EnumState .ToString() == "NewYork".ToString())
{
value = "New York".ToString();
EnumState = value;
}
}
}
I have seen this generally handled by putting a
[StringValue("New York")]attribute on the enum members. A quick google search returns this blog post, which has a pretty good way of doing it.Basically make the attribute class:
And an extension method to access it:
Then your enum would look like this:
and you can just use
myState.GetStringValue();