컴파일러 오류 CS0191
업데이트: 2007년 11월
오류 메시지
'name' 속성 또는 인덱서는 읽기 전용이므로 할당할 수 없습니다.
Property or indexer 'name' cannot be assigned to -- it is read only
readonly 필드는 생성자 안에서 또는 선언할 때만 할당할 수 있습니다. 자세한 내용은 생성자(C# 프로그래밍 가이드)를 참조하십시오.
CS0191은 readonly 필드가 static이고 생성자가 static으로 표시되지 않은 경우에도 발생합니다.
예제
다음 샘플에서는 CS0191 오류가 발생하는 경우를 보여 줍니다.
// CS0191.cs
class MyClass
{
public readonly int TestInt = 6; // OK to assign to readonly field in declaration
MyClass()
{
TestInt = 11; // OK to assign to readonly field in constructor
}
public void TestReadOnly()
{
TestInt = 19; // CS0191
}
public static void Main()
{
}
}