'this' in C#.Net
In C#.Net ‘this’ is a reference of current object, which is accessible within the class only.
To access an element of class by referencing current object of it, we use this keyword, remember following points:
- this keyword is used.
- this cannot be used with the static member functions.
-
Consider the program:
Output
In above program within setValues() method, this is used to differentiate between data member of class and local variable of method. Because this is a reference of current class object it can be used as data member.