Level 4 — Classes
Getters and Setters
Original notes by SunDiaL · View English source
Getters and Setters are a particular type of methods. They are defined and invoked as any other method, but they serve a very specific purpose, that of controlling field reading and writing.
class ExampleClass
{
private int x;
public int GetX()
{
return this.x;
}
public void SetX(int newValue)
{
this.x = newValue;
}
}