If I have the following code:
public enum Greatings
{
Hi,
Hola,
}
private static class General
{
public static string stringKey = "Hi"
public static Greatings enumKey { get; set; }
}
Since I know that enumKey
is a value of the enum type Greatings, is there a way of assigning enumKey.Assign(stringKey)
?
I have been able to do something like this:
public static T Assign<T>(string value) where T : struct
{
return (T)Enum.Parse(typeof(T), value);
}
And then call enumKey = Assign<Greatings>(stringKey)
but I wish I didn’t need to use the explicit Greatings
because I might have more properties and different type of enums so if I have a function that links to the property that is going to be modified, it would be perfect.
10