컴파일러 오류 CS0842
업데이트: 2007년 11월
오류 메시지
자동으로 구현된 속성은 StructLayout(LayoutKind.Explicit)으로 표시된 형식 내부에서 사용할 수 없습니다.
Automatically implemented properties cannot be used inside a type marked with StructLayout(LayoutKind.Explicit).
자동으로 구현된 속성에는 컴파일러에서 제공한 지원 필드가 있으며 소스 코드에서는 이 필드에 액세스할 수 없습니다. 따라서 이 필드는 LayoutKind.Explicit와 함께 사용할 수 없습니다.
이 오류를 해결하려면
- 속성을 접근자 본문을 제공한 일반 속성으로 만듭니다.
예제
다음 예제에서는 CS0842 오류가 발생하는 경우를 보여 줍니다.
// cs0842.cs
using System;
using System.Runtime.InteropServices;
namespace TestNamespace
{
[StructLayout(LayoutKind.Explicit)]
struct Str
{
public int Num // CS0842
{
get;
set;
}
static int Main()
{
return 1;
}
}
}