class Person
{
string name;
public Person(string name)
{
this.name = name;
}
public void method()
{
Person gupta = new Person("James"); // Current Object
Console.WriteLine(this.name);
Person gupta1 = new Person("Peter"); // Current Object
Console.WriteLine(this.name);
Person gupta2 = new Person("Frank"); // Current Object
Console.WriteLine(this.name);
}
static void Main(string[] args)
{
Person p = new Person("Jim");
p.method();
Console.ReadLine();
}
}
This code produced result
Jim
Jim
Jim
However if thought this should be
James
Peter
Frank
Can somebody explain please?
Maybe if you re-write your code as:
You'll better appreciate how "this" works.