C# | this Keyword Last Updated : 15 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 csharp // C# program for using 'this' keyword to // refer current class instance members using System; namespace geeksforgeeks { class Geeks { // instance member public string Name; public string GetName() { return Name; } public void SetName(string Name) { // referring to current instance //"this.Name" refers to class member this.Name = Name; } } class program { // Main Method public static void Main() { Geeks obj = new Geeks(); obj.SetName("Geeksforgeeks"); Console.WriteLine(obj.GetName()); } } } Output: Geeksforgeeks Program 2 : Using this() to invoke the constructor in same class csharp // C# program for using 'this' keyword to // invoke the constructor in same class using System; namespace geeksforgeeks { class Geeks { // calling another constructor // calls Geeks(string Name) // before Geeks() public Geeks() : this("geeks") { Console.WriteLine("Non-Parameter Constructor Called"); } // Declare Parameter Constructor public Geeks(string Name) { Console.WriteLine("Parameter Constructor Called"); } } class program { // Main Method public static void Main() { Geeks obj = new Geeks(); // Warning: obj never used.. } } } Output: Parameter Constructor Called Non-Parameter Constructor Called Program 3: Using ‘this’ keyword to invoke current class method csharp // C# code for using this to invoke current // class method using System; class Test { void display() { // calling function show() this.show(); Console.WriteLine("Inside display function"); } void show() { Console.WriteLine("Inside show function"); } // Main Method public static void Main(String []args) { Test t1 = new Test(); t1.display(); } } OutputInside show function Inside display function Program 4: Using ‘this’ keyword as method parameter csharp // C# code for using 'this' // keyword as method parameter using System; class Test { int a; int b; // Default constructor Test() { a = 10; b = 20; } // Method that receives 'this' // keyword as parameter void display(Test obj) { Console.WriteLine("a = " + a + " b = " + b); } // Method that returns current // class instance void get() { display(this); } // Main Method public static void Main(String[] args) { Test obj = new Test(); obj.get(); } } Output: a = 10 b = 20 Program 5: Using this keyword to declare an indexer csharp // C# code for using 'this' // keyword to declare indexer using System; namespace geeksforgeeks { class Geeks { private string[] days = new string[7]; // declaring an indexer public string this[int index] { get { return days[index]; } set { days[index] = value; } } } class Program { // Main Method public static void Main() { Geeks g = new Geeks(); g[0] = "Sun"; g[1] = "Mon"; g[2] = "Tue"; g[3] = "Wed"; g[4] = "Thu"; g[5] = "Fri"; g[6] = "Sat"; for (int i = 0; i < 7; i++) Console.Write(g[i] + " "); } } } Output: Sun Mon Tue Wed Thu Fri Sat Comment More infoAdvertise with us Next Article ushort keyword in C# M Mithun Kumar Follow Improve Article Tags : Misc C# CSharp-keyword Practice Tags : Misc Similar Reads C# Keywords Keywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to be used as variable names or objects. Doing this will result in a compile-time error.Example:C#// C# Program to illustrate the 5 min read JavaScript this Keyword The 'this keyword' in JavaScript refers to the object to which it belongs. Its value is determined by how a function is called, making it a dynamic reference. The 'this' keyword is a powerful and fundamental concept used to access properties and methods of an object, allowing for more flexible and r 4 min read uint keyword in C# Keywords are the words in a language that are used for some internal process or represent some predefined actions. uint is a keyword that is used to declare a variable which can store an integral type of value (unsigned integer) from the range of 0 to 4,294,967,295. It keyword is an alias of System. 2 min read sbyte Keyword in C# Keywords are the words in a language that are used for some internal process or represent some predefined actions. SByte is a keyword that is used to declare a variable that can store a signed value between the range of -128 to +127. It is an alias of System.SByte. SByte keyword occupies 1 byte (8 b 2 min read ushort keyword in C# Keywords are the words in a language that are used for some internal process or represent some predefined actions. ushort is a keyword that is used to declare a variable which can store an unsigned integer value from the range 0 to 65,535. It is an alias of System.UInt16. Syntax: ushort variable_nam 2 min read ulong keyword in C# Keywords are the words in a language that are used for some internal process or represent some predefined actions. ulong is a keyword that is used to declare a variable which can store an unsigned integer value from the range 0 to 18,446,744,073,709,551,615. It is an alias of System.UInt64. ulong ke 2 min read Like