Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am a new programmer i c#. can sumone explain me the sigificane of this keyword with a suitable example ?
Posted

The simple explanation is:
this always points to the object that the currently executing code belongs to.

For a more sophisticated answer, read the given MSDN link.

Or feel free to elaborate on your question or comment on an answer.
 
Share this answer
 
Comments
pradeep kumar tarei 15-Mar-12 8:06am    
thankx lukeer
pradeep kumar tarei 15-Mar-12 8:08am    
just tell me 1 more thing. even if we dont use this keyword ,still the code executes. than what is the advantage of using "this".
lukeer 17-Mar-12 6:44am    
The advantage is that a developer looks at the code and immediately knows where a method or property or whatever belongs to.
pradeep kumar tarei 17-Mar-12 8:32am    
thankx
Read this[^]

hope it helps :)
 
Share this answer
 
Comments
pradeep kumar tarei 15-Mar-12 3:18am    
any simplification solution other than msdn ?
Hi,

In addition to that you can also use this keyword in Extension methods(.Net 3.5).
For more info check here.
 
Share this answer
 
Comments
pradeep kumar tarei 15-Mar-12 8:09am    
thankx laxman !!
just tell me 1 more thing. even if we dont use this keyword ,still the code executes. than what is the advantage of using "this".
Lakxman 15-Mar-12 8:29am    
Suppose say you have a constructor that contains two parameters and you want to initialize the local variables which are of same name as the parameters, 'this' keyword would be useful. EX:
public MyConstructor(int age, string name)
{
this.age= age;
this.name= name;
}
here the 'this' keyword here will qualify the fields.
pradeep kumar tarei 15-Mar-12 8:42am    
thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900