csharp / beginner
Snippet
Auto-Implemented Properties
Properties provide a flexible mechanism to read, write, or compute the value of a private field. Auto-properties simplify this by letting the compiler handle the private field for you.
snippet.csharp
1
2
3
4
public class Player {public string Nickname { get; set; }public int Score { get; private set; }}
Breakdown
1
{ get; set; }
Allows both reading and writing to the property.
2
{ get; private set; }
Allows anyone to read the value, but only code inside the class can change it.