Since there are several modes in my game (which should be provided during initialization), I thought about creating an enumeration for it. Later I wanted to get the meaning of this listing. Below is my code -
enum GameMode : short
{
Stop = 0,
StartSinglePlayer = 4,
StartMultiPlayer = 10,
Debug = 12
}
class Game
{
static short GetValue(GameMode mode)
{
short index = -1;
if (mode == GameMode.Stop)
index = 0;
else if (mode == GameMode.StartSinglePlayer)
index = 4;
else if (mode == GameMode.StartMultiPlayer)
index = 10;
else if (mode == GameMode.Debug)
index = 12;
return index;
}
static void Main(string[] args)
{
var value = GetValue(GameMode.StartMultiPlayer);
}
}
I am curious about the best way to do the same, if it exists.
source
share