So I’ve seen this. in code a bunch of places. I’ve seen it here is C#, and now I’ve seen it in Java Script for something else. I’ve been trying to figure out what “this.” does. (I feel like I’m in the who’s on first skit). You can’t google it because “this” is ubiquitous to every paragraph of English language. Of course, now that I’m looking for an example, I can’t find one.
So can someone point me to a document that explains what it means when I see this.something ?
And yes I’m aware that it’s probably some super basic code thing that most coders probably already know…
This refers to the current instance of an object (called internally within a class)
For example if you have a class called Person with a property called name and a method which takes “another” instance of the person class and assigns its name to “this one” you would use this
class Person
{
public string Name {get;set;}
public void CopyNameFromPerson(Person p)
{
this.Name = p.Name; //Meaning assign the name property of the person P to my current instance of Person (me, this)
}
}