컴파일러 오류 CS1650
업데이트: 2007년 11월
오류 메시지
정적 읽기 전용 필드 'identifier'의 필드에는 할당할 수 없습니다. 단 정적 생성자 또는 변수 이니셜라이저에서는 예외입니다.
Fields of static readonly field 'identifier' cannot be assigned to (except in a static constructor or a variable initializer)
이 오류는 수정할 수 없는 정적 읽기 전용 필드의 멤버를 수정하는 경우에 발생합니다. 이 오류를 해결하려면 읽기 전용 필드의 할당을 생성자 또는 변수 이니셜라이저로 제한하거나 필드 선언에서 readonly 키워드를 제거합니다.
// CS1650.cs
public struct Inner
{
public int i;
}
class Outer
{
public static readonly Inner inner = new Inner();
}
class D
{
static void Main()
{
Outer.inner.i = 1; // CS1650
}
}