Error CS0840: Automatically implemented properties must define both get and set accessors

Auto implemented properties are wonderful thins and save lot of coding and declaration in most of the situations. So a simple auto implemented property will look like as below.

public string Title
{get; set;}

No need to define a private variable to store the value. In some cases you want your property to be immutable meaning you don't want clients to be able to change the value and only allow private or internal access to the setter of this property. The specification of auto implemented properties says that you have to provide both get and set accessors. This does not mean that you have to provide public accessors for both. You can always provide private or inernal accessor for get.

public string Title
{get; internal set;}




5.1 °C / 41.1 °F

weather conditions Clouds

Monthly Posts

Blog Tags