I have an enumeration, which contains hundreds of entries.
I will be getting the value of the enumeration as a string. Is there any way to convert the string into an enum value? Otherwise, I will end up using hundreds of if statements.
Consider
enum Colors { Red, Green, Blue, Yellow ... } there are more than 100 entries
I will be getting "Red"
in a string variable,
String color = "Red"; // "Red" would be generated dynamically.
Normally we access the enum in the following way,
Colors::Red
, Colors::Blue
etc...
is there any way in which we can access it in a way something like this:
Colors::color; // i.e enumtype::stringVariable
In many posts here, it’s given that we can use map, but again while constructing map we will end up in using hundreds of if
s.
Is there any way to avoid this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…