What is the difference b/w the following two codes. What is the use of using ‘this’ keyword in the constructor.
Ex 1:
public Product(string name){
this.Name = name;
}
Ex 2:
public Product(string name){
Name = name;
}
I know this refers to the calling object. Just I couldn’t able to get the difference?
can some one please explain?
Example 1 uses an explicit reference to
this. This is not really needed as there’s no ambiguity in this case. If the parameter was calledNameinstead, the explicitthiswould be required to resolve the ambiguity.