컴파일러 오류 CS0840

업데이트: 2007년 11월

오류 메시지

'Property name'은(는) abstract 또는 extern으로 표시되어 있지 않으므로 본문을 선언해야 합니다. 자동으로 구현된 속성은 get 및 set 접근자를 정의해야 합니다.
'Property name' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.

일반 속성이 abstract 또는 extern으로 표시되어 있지 않거나 partial 형식의 멤버가 아니면 본문을 제공해야 합니다. 자동으로 구현된 속성은 접근자 본문을 제공하지 않지만 두 접근자를 모두 지정해야 합니다. 자동으로 구현된 읽기 전용 속성을 만들려면 set 접근자를 private로 만듭니다.

이 오류를 해결하려면

예제

다음 예제에서는 CS0840 오류가 발생하는 경우를 보여 줍니다.

// cs0840.cs
// Compile with /target:library
using System;
class Test
{
    public int myProp { get; } // CS0840

    // to create a read-only property
    // try the following line instead
    public int myProp2 { get; private set; }
    
}

참고 항목

참조

자동으로 구현된 속성(C# 프로그래밍 가이드)