Created
May 15, 2016 13:49
-
-
Save insideone/d273a0316e8ecd2aa8dc4f6bd7495551 to your computer and use it in GitHub Desktop.
C#: enum work example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum EmpType | |
{ | |
Дворник = 403, | |
Программист, | |
Президент | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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