다음을 통해 공유


컴파일러 오류 CS0283

'type' 형식은 const로 선언할 수 없습니다.

상수 선언에 지정된 형식은 byte, sbyte, ushort, short, uint, int, ulong, long, char, float, double, decimal, bool, string, 열거형 형식 또는 null 값이 할당된 참조 형식이어야 합니다. 각 상수 식은 대상 형식의 값 또는 암시적으로 대상 형식으로 변환 가능한 형식의 값을 생성해야 합니다.

예시

다음 예제에서는 CS0283을 생성합니다.

// CS0283.cs  
struct MyTest  
{  
}  
class MyClass
{  
    // To resolve the error but retain the "const-ness",  
    // change const to readonly.  
    const MyTest test = new MyTest();   // CS0283  
  
    public static int Main() {  
        return 1;  
    }  
}