Property

Property (C#)

A property in C# is a member of a class that provides controlled access to a value. It looks like a variable when you use it, but it’s backed by get and set accessors that control how the value is read and written.

Auto-Property#

The simplest form is the auto-property. The compiler generates the backing storage automatically.

public class Player
{
    public int WinCount { get; set; }
}
  • get — allows the value to be read
  • set — allows the value to be written

Using it looks exactly like using a variable: