Have you failed a job interview?
Send us your job interview questions and get correct answers.

What is 'this' keyword used for in C#?

Experience Level: Junior
Tags: C#


'this' keyword works like a reference to an object that holds the method that is currently being executed. In the example below the 'this' keyword is used to refer to the property VolumeLevel. The keyword 'this' is not needed most of the time, so whenever you see it, you should be thinking whether the keyword is really needed and whether it couldn't be removed.

public class Radio 
  public int VolumeLevel { get; set; }

  public void ShowVolume() 
    var currentVolumeLevel = this.VolumeLevel;


No Comments Yet.
Be the first to tell us what you think.
C# for beginners
C# for beginners

Are you learning C# ? Try our test we designed to help you progress faster.

Test yourself