I'm trying to determine if a string value read-in from a file is found within an enum in my code.
The enum:
internal enum Difficulty { None, Easy, Medium, Hard }
At this point in my code header[i] = "EASY".
I want to compare this value to any of the values found in my Difficulty enum but am encountering issues.
The code:
Each time the following code is executed, the if statement returns false because "Easy" != "EASY".
Difficulty dif = Difficulty.None;
if (Difficulty.TryParse(header[i], out dif)) { // RETURNS FALSE
MyLog.Write("It's in the Enum!");
}
I've tried comparing the header[i] value to the Difficulty value in the TryParse statement, but it results in a compiler error.
Is there anything I can do besides changing all the Difficulty values to uppercase ones?