string input=Console.ReadLine();
Weapon wName = (Weapon)Enum.Parse(typeof(Weapon), input, true);
입력 받은 문자열을 열거형으로 변환한다.
true는 대소문자를 구분하지 않는다.
false면 구분한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
namespace Study_005
{
class App
{
//열거형
enum Weapon
{
Sword, //0
Bow, //1
Axe //2
}
public App()
{
Console.WriteLine("2020-04-08\n");
Console.Write("착용할 아이템의 이름을 입력하세요 ");
string input=Console.ReadLine();
//문자열을 열거형으로 변환한다.
Console.WriteLine("{0}를 착용합니다. ",wName);
}
}
}
|
'C# > 수업내용' 카테고리의 다른 글
2020.04.09. 수업내용 - 아이템 착용, 해제 (if, switch) (0) | 2020.04.09 |
---|---|
2020.04.09. 수업내용 - 아이템 확률적으로 강화하기(열거형, Switch) (0) | 2020.04.09 |
2020.04.08. 수업내용 - 열거형 변환 (캐스팅 ( ) ) (0) | 2020.04.08 |
2020.04.08. 수업내용 - 유닛 좌우 움직이기 (특정위치 아이템) (0) | 2020.04.08 |
2020.04.08. 수업내용 - 반복문 연습 (줄넘기) (0) | 2020.04.08 |