mdr141
12/24/2018 - 1:43 AM

CSharp_Enum

/NOT YET/

using System;

namespace TestEnum
{
    class Program
    {
        static void Main(string[] args)
        {
            var se = new EnumSeason();
            // s.PrintSeason(2); はエラー
            se.PrintSeason(EnumSeason.Season.Autumn);                  // OUTPUT: Autumn
            // 列挙型の書式を整数値に指定「ToString("D")」
            Console.WriteLine(EnumSeason.Season.Autumn.ToString("D")); // OUTPUT: 2
            // 列挙型の書式を16進数に指定「ToString("X")」
            Console.WriteLine(EnumSeason.Season.Autumn.ToString("X")); // OUTPUT: 00000002
        }
    }

    public class EnumSeason
    {
        public enum Season
        {
            Spring, // 0
            Summer, // 1
            Autumn, // 2
            Winter, // 3
        }

        public void PrintSeason(Season season)
        {
            Console.WriteLine(season);
        }
    }

}