Introduction
The getter is a shorthand way to access the variable.
The setter is a shorthand way to change its value of the variable.
Each member can have either have 1 getter, 1 setter or both (1 getter + 1 setter).
getter
In C#, the keyword get specifies what the getter will do.
setter
In C#, the keyword set specifies what the setter will do.
Example
public string name_
{
get {return this.nickname;}
set {this.nickname = value;}
}
public Image
{
private string nickname;
}
static void Main(string args[])
{
Image image = new Image;
// No compiler error. It will call the setter of name_ .
image.name_ = "name1";
// Compiler error due to nickname is private in protection level.
image.nickname = "name1";
}