VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-this-keyword/

⇱ C# | this Keyword - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | this Keyword

Last Updated : 15 Nov, 2021

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
 


Output: 
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 
 


Output
Inside show function
Inside display function

Program 4: Using ‘this’ keyword as method parameter 
 


Output: 
a = 10 b = 20

 

Program 5: Using this keyword to declare an indexer 
 


Output: 
Sun Mon Tue Wed Thu Fri Sat

 
Comment
Article Tags:

Explore