상수와 열거 형식은 변수와 달리 안에 담긴 데이터를 절대 바꿀 수 없는 메모리 공간입니다.

상수

const int a = 3;
const double b = 3.14;
const string c = "abcdef";

열거 형식

enum DialogResult { YES, NO, CANCEL, CONFIRM, OK}

아무것도 지정하지 않은 경우에 첫 번째 요소는 0, 그 다음 요소는 1, 그다음 요소는 2…라는 식으로 선언된 순서에 따라 1씩 증가된 값을 컴파일러가 자동으로 할당합니다.

// 사용예시

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hello
{
    internal class Enum_ex
    {
        class MainApp
        {
            enum DialogResult { YES, NO, CANCEL, CONFIRM, OK }

            static void Main(string[] args)
            {
                Console.WriteLine((int)DialogResult.YES);
                Console.WriteLine((int)DialogResult.NO);
                Console.WriteLine((int)DialogResult.CANCEL);
                Console.WriteLine((int)DialogResult.CONFIRM);
                Console.WriteLine((int)DialogResult.OK);
            }
						// 결과
            // 0
            // 1
            // 2
            // 3
            // 4
        }
    }
}

프로그래머가 원하는 값을 직접 대입할 경우

enum DialogResult {YES = 10, NO, CANCEL, CONFIRM = 50, OK}