Не могу разобраться с enum - C#
Формулировка задачи:
Здравствуйте!
Создал вот такое перечисление
Далее, я хочу, чтобы я мог, к примеру, ввести из клавиатуры число 1 и мне на экран вывело Specialist, когда 2 - Bachelor и так далее.
Для этого я создал свойства get и set:
И вот в главном класне, в методе Main, я заплутался, тоесть не знал, как правильно обратиться к свойствам, сделал как-то так:
В итоге, какое число я бы не вводил, у меня выводило 0.
В чем моя ошибка?
public enum Education { Specialist = 1, Вachelor, SecondEducation }; public Education Form_of_education
{
set {
int num = Convert.ToInt32(Console.Read());
switch (num)
{
case 1:
form_of_education = Education.Specialist;
break;
case 2:
form_of_education = Education.SecondEducation;
break;
case 3:
form_of_education = Education.Вachelor;
break;
}
}
get
{
return form_of_education;
}static void Main(string[] args)
{
Student anton = new Student();
Student.Education p = new Student.Education();
anton.Form_of_education = p;
Console.WriteLine(anton.Form_of_education);
Console.ReadKey();
}Решение задачи: «Не могу разобраться с enum»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14 {
class Program {
static void Main(string[] args) {
Numbers number = Numbers.TWO;
Console.WriteLine((int)number);
int n = 4;
Console.WriteLine((Numbers)n);
Console.ReadLine();
}
}
enum Numbers {
ONE=1,
TWO,
THREE,
FOUR,
FIVE
}
}