Share via


컴파일러 오류 CS0198

업데이트: 2007년 11월

오류 메시지

정적 읽기 전용 필드 'name'의 필드에는 할당할 수 없습니다. 단 정적 생성자 또는 변수 이니셜라이저에서는 예외입니다.
Fields of static readonly field 'name' cannot be assigned to (except in a static constructor or a variable initializer)

생성자의 readonly 변수를 초기화하려는 경우, 이 변수에는 해당 생성자와 동일하게 static을 사용해야 합니다. 자세한 내용은 정적 생성자(C# 프로그래밍 가이드)를 참조하십시오.

다음 샘플에서는 CS0198 오류가 발생하는 경우를 보여 줍니다.

// CS0198.cs
class MyClass
{
   public static readonly int TestInt = 6;

   MyClass()
   {
      TestInt = 11;   // CS0198, constructor is not static and readonly field is
   }

   public static void Main()
   {
   }
}