Skip to content

Instantly share code, notes, and snippets.

@insideone
Created May 15, 2016 13:49
Show Gist options
  • Save insideone/d273a0316e8ecd2aa8dc4f6bd7495551 to your computer and use it in GitHub Desktop.
Save insideone/d273a0316e8ecd2aa8dc4f6bd7495551 to your computer and use it in GitHub Desktop.
C#: enum work example
enum EmpType
{
Дворник = 403,
Программист,
Президент
}
static void Main(string[] args)
{
EmpType IAM = EmpType.Дворник;
int x = (int)IAM;
string data = EmpType.Дворник.ToString();
do
{
if (Enum.IsDefined(typeof(EmpType), data))
{
if (IAM.ToString() == data)
Console.WriteLine("Я уже " + data);
else
{
IAM = (EmpType)Enum.Parse(IAM.GetType(), data, true);
Console.WriteLine("Теперь я " + IAM.ToString());
}
}
else
{
Console.WriteLine("А кто такой {0}?", data);
}
do
{
Console.WriteLine("Вы {0}, но можете сменить профессию: [введите цифру или строку]", IAM.ToString());
foreach (EmpType val in Enum.GetValues(typeof(EmpType)))
Console.WriteLine("{0:d}. {0}", val);
data = Console.ReadLine();
if (Char.IsDigit(data[0]))
{
string temp = Enum.GetName(typeof(EmpType), int.Parse(data));
if (temp == null)
{
Console.WriteLine("Идентификатор профессии {0} не найден!", data);
continue;
}
else
data = temp;
}
else
data.Trim();
} while (false);
} while (data != null && data != "exit");
Console.WriteLine("В конце концов я " + IAM.ToString());
Console.ReadLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment