컴파일러 오류 CS1649
업데이트: 2007년 11월
오류 메시지
읽기 전용 필드 'identifier'의 멤버는 ref 또는 out으로 전달할 수 없습니다. 단 생성자에서는 예외입니다.
Members of readonly field 'identifier' cannot be passed ref or out (except in a constructor)
이 오류는 readonly 필드의 멤버인 변수를 ref 또는 out 인수로 함수에 전달할 때 발생합니다. ref 및 out 매개 변수는 함수에 의해 수정되지 않으므로 이 작업을 수행할 수 없습니다. 이 오류를 해결하려면 필드에서 readonly 키워드를 제거하거나, readonly 필드의 멤버를 함수에 전달하지 마십시오. 예를 들어, 다음 예제와 같이 수정 가능한 임시 변수를 만들어 ref 인수로 전달할 수 있습니다.
예제
다음 샘플에서는 CS1649 오류가 발생하는 경우를 보여 줍니다.
// CS1649.cs
public struct Inner
{
public int i;
}
class Outer
{
public readonly Inner inner = new Inner();
}
class D
{
static void f(ref int iref)
{
}
static void Main()
{
Outer outer = new Outer();
f(ref outer.inner.i); // CS1649
// Try this code instead:
// int tmp = outer.inner.i;
// f(ref tmp);
}
}