KDT/C# 프로그래밍

디아블로 아이템 열거형식(enum)

잰쟁 2023. 7. 20. 12:01
728x90
using System;
using System.Runtime.InteropServices;

namespace LearnDotnet
{
    internal class Program
    {
        enum Items
        {
            HELMS,
            WEAPONS,
            POTIONS
        }
        static void Main(string[] args)
        {
            //상수정의
            const int HELMS = 0;
            const int WEAPONS = 1;
            const int POTIONS = 2;

            //변수정의
            Items items;

            //값 할당
            items = Items.POTIONS;

            //값 출력
            Console.WriteLine("items: {0}", items);

            //Items -> int 형식 변환
            int intItems = (int)items;
            Console.WriteLine(intItems);

            //int -> Items로 형식 변환
            int intPotions = 2;
            Items potions = (Items)intPotions;
            Console.WriteLine("items: {0}", potions);
        }
    }
}