Share via


컴파일러 오류 CS1648

업데이트: 2007년 11월

오류 메시지

읽기 전용 필드 'identifier'의 멤버는 수정할 수 없습니다. 단 생성자 또는 변수 이니셜라이저에서는 예외입니다.
Members of readonly field 'identifier' cannot be modified (except in a constructor or a variable initializer)

이 오류는 수정할 수 없는 읽기 전용 필드의 멤버를 수정하는 경우에 발생합니다. 이 오류를 해결하려면 읽기 전용 필드의 할당을 생성자 또는 변수 이니셜라이저로 제한하거나 필드 선언에서 readonly 키워드를 제거합니다.

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

// CS1648.cs
public struct Inner
  {
    public int i;
  }

class Outer
{  
  public readonly Inner inner = new Inner();
}

class D
{
   static void Main()
   {
      Outer outer = new Outer();
      outer.inner.i = 1;  // CS1648
   }
}