Properties and Accessors


Use of new revised syntax for declaring properties and accessor.

The compiler automatically creates normal property get and set accessors and a backing field.

Code Example

You don't care about the name of the backing field because you access it only through the get and set accessors, never directly.

public String LastName { get; set; } public String FirstName { get; set; }

Read-only properties aren't allowed with this shortcut syntax because you could never set the value. To simulate read-only behaviour, do the following:

public Int32 ID { get; private set; }