Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.39 KB

File metadata and controls

42 lines (31 loc) · 1.39 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Compiler Error CS0840
Compiler Error CS0840
07/20/2015
CS0840
CS0840
f307083f-8d86-4142-a9fd-b735910687b2

Compiler Error CS0840

'Property name' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.

Unless a regular property is marked as abstract or extern, or is a member of a partial type, it must supply a body. Auto-implemented properties do not provide accessor bodies, but they must specify both accessors. To create a read-only auto-implemented property, make the set accessor private.

To correct this error

  1. Supply the missing body or accessor or else use the abstract, extern, or partial (Type) modifiers on it and/or its enclosing type.

Example

The following example generates 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; }  
  
}  

See also