this / self
The keyword a method uses to refer to the object it was called on.
What does this / self do?
this (C#, Java, JavaScript) or self (Python) is how code inside a method refers to the current object: the one the method was called on.
public class Person
{
private string name;
public Person(string name)
{
this.name = name; // this.name = the object's field; name = the parameter
}
}
Level: Apprentice · More OOP terms at this level
Updated