![]() |
VOOZH | about |
this keyword is used to refer to the current instance of the class. It is used to access members from the constructors, instance methods, and instance accessors. this keyword is also used to track the instance which is invoked to perform some calculation or further processing related to that instance. Following are the different ways to use ‘this’ keyword in C# :
Program 1: Using ‘this’ keyword to refer current class instance members
Geeksforgeeks
Program 2 : Using this() to invoke the constructor in same class
Output:
Parameter Constructor Called Non-Parameter Constructor Called
Program 3: Using ‘this’ keyword to invoke current class method
Inside show function Inside display function
Program 4: Using ‘this’ keyword as method parameter
a = 10 b = 20
Program 5: Using this keyword to declare an indexer
Sun Mon Tue Wed Thu Fri Sat