class Perl
{
private int value;
public Perl()
{
this.value++;
}
public void display()
{
Console.WriteLine("B called: " + this.value);
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Perl perl1=new Perl()
perl1.display();
Perl perl2=new Perl()
perl2.display();
}
}
}
So I have been reading tutorial on "this" here and there trying out example codes and see what happens when I take out "this" from variables. From my understanding, "this" is a reference to an object (instance of a class) such as perl1 and perl2 in the code.
When I took out "this" from "this.value++" and "this.value", "value" and "this.value" remained the same. Is "this" even needed in this case since perl1 and perl2 are instantiated and have their own variables? (perl1's value and perl2's value are separate right?) If that's the case, why is "this" even needed or used since all the variables belong to the separate objects?
I want to start using "this", but every time I try to learn about it, the more confused I get.
Would someone explain this to me?