Share via


컴파일러 오류 CS1959

업데이트: 2007년 11월

오류 메시지

'name'은(는) 'type' 형식입니다. 상수 선언에 지정되는 형식은 sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, string, enum-type 또는 reference-type이어야 합니다.
'name' is of type 'type'. The type specified in a constant declaration must be sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, string, an enum-type, or a reference-type.

상수 선언에는 이 메시지에 나와 있는 형식만 사용할 수 있습니다.

이 오류를 해결하려면

  • 허용되는 형식의 상수를 선언합니다.

예제

다음 코드에서는 null이 형식이 아니기 때문에 CS1959 오류가 발생하는 경우를 보여 줍니다.

// cs1959.cs
class Program
    {
        static void Test<T>() where T : class
        {
            const T x = null; // CS1959
        }
    }

참고 항목

참조

상수(C# 프로그래밍 가이드)

null(C# 참조)