카테고리 없음

열거형(enum) 연습

노재두내 2023. 7. 20. 11:59
using System;

namespace LearnDotnet
{
    internal class Program
    {
        //item
        //무기,방어구,물약 상수로 정의
        //그룹화 해서 열거형식으로 만들자
        //열거형식 xxx로 변수를 정의하고
        //변수의 값을 할당 후 출력
        //또한 열거형식 멤버를 정수형으로 캐스팅 하고
        //정수형식을 다시 열거형으로 캐스팅 하는 연습을 해보자
        enum Weapons
        {
            WEAPON,
            POTION,
            ARMOR
        }
        static void Main(string[] args)
        {
            int WEAPON = 0;
            int POTION = 1;
            int ARMOR = 2;

            Weapons weapon;
            weapon = Weapons.WEAPON;

            Console.WriteLine("weapon:{0}", weapon);

            //Weapons->int

            int intWeapons = (int)weapon;
            Console.WriteLine(intWeapons);

            //int->Weapon 형식으로 변환
            int intPotion = 0;
            Weapons potion = (Weapons)intPotion;
            Console.WriteLine(potion);

        }
    }
}