Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

What does the this keyword mean in C#?

Hi everyone! 😀

I'm a bit confused with the this keyword here 😕. What I've read in the C# documentation is that this is a keyword that references to the current object. So I've dropped my questions down below.

What is the current object in this context? When and why should you the this keyword?

public class Customer
{
    public string Name;

    public Customer(string name) {
        this.Name = name;
    }
}

1 Answer

Reggie Williams
STAFF
Reggie Williams
Treehouse Teacher

Hey Kevin, the current object in this context is an instance of customer. When constructing a customer it this.Name provides scope and refers to "this customer's name"