2
Reply

What is the "this" keyword in C# ?

Santosh Kumar

Santosh Kumar

13y
6.4k
0
Reply

    Every technology must have a default constructor. 'this' is a reference variable of default constructor that hold the all reference id of the class. 

    C# supports the keyword "this" which is a reference to the object that called the method. The "this" reference is available within all the member method and always refers to the current instance. It is normally used to distinguish between the local and instance variables that have the same name. The "this" reference is a hidden reference passed to every non-static method of a class. Consider the code -

    class temp {
    int x, y;
    public void setXY(int x, int y) {
    this.x =x;
    this.y =y; } }

    In the assignment statement, this.x and this.y refer to the class member named y and y whereas simple x and y refer to the parameter of the setXY() method.