← Back to C# Course | Chapter 6: OOP Basics | Lesson 7 of 7

The this Keyword

In this page:

  1. The this Keyword

The this Keyword

this refers to the current object instance inside a non-static method or constructor. It's most often used to disambiguate an instance field from a parameter of the same name. this can also be used to call another constructor on the same class.

Note: Use this.fieldName = fieldName; in a constructor when the parameter shares the field's name.

Example: The this Keyword

markup
using System;

class Rectangle
{
    public int Width;
    public int Height;

    public Rectangle(int width, int height)
    {
        this.Width = width;
        this.Height = height;
    }

    public int Area()
    {
        return this.Width * this.Height;
    }
}

class Program
{
    static void Main(string[] args)
    {
        Rectangle r = new Rectangle(4, 5);
        Console.WriteLine(r.Area());
    }
}
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.