Maha

Maha

  • NA
  • 0
  • 324k

this reference

Mar 5 2012 10:17 AM
In a book examples, this reference is used within the instance method & in constructor. That means used within the get() and set() method and in constructor.

In my view if you are using this reference within set() method you don't need to use within the get() method. I wish to know whether my understanding is correct. I enclosed an example program.


using System;
namespace _7e7
{
class Program
{
static void Main(string[] args)
{
Salesperson sp = new Salesperson("Hendry Ford");
Console.WriteLine(sp.getSalesPfullName());

Console.ReadKey();
}
}
}
class Salesperson
{
string name;

public Salesperson(string name)
{
this.name = name;
}

public string getSalesPfullName()
{
return name; //Note: no this reference is used 
}
}
/*
Hendry Ford
*/


Answers (3)