0

I would like to know if it is possible to convert an enum key to a string and a string to an enum key like follow:

enum AllGameSettingsLabels {
    Options_Controls_Joystick_Sensitivity,
    Options_Display_Screen_Resolution,
    Game_Character_Name
    // ...
}

IDictionary<AllGameSettingsLabels, string> settings = new Dictionary<AllGameSettingsLabels, string>();

settings[AllGameSettingsLabels.Parse(AllGameSettingsLabels.Joystick_Sensitivity.ToString() + "_Player_1")] = (0.25).ToString();

I was trying to come up with an easy way to manage all the game settings and later converting them to JSON.

Trafel
  • 79
  • 2
  • 10
  • See https://learn.microsoft.com/en-us/dotnet/api/system.enum.parse?view=netframework-4.8 – auburg Feb 11 '20 at 16:45
  • 2
    JSON serialization will do that for you automagically so you don't need to worry about converting string to enum and vice-verse. Does this answer your question? [Deserialize Json string to Enum C#](https://stackoverflow.com/questions/56386362/deserialize-json-string-to-enum-c-sharp) – Prix Feb 11 '20 at 16:46

0 Answers0