Log in from a computer to take this course

You'll need to log in from a computer to start Learn C#. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store

In the last exercise we assigned the area field in the constructor:

class Forest { public int Area { /* property omitted */ } public Forest(int area) { Area = area; } }

The parameter for the constructor area looks a lot like the old field area and the new property Area. It’s good to be explicit when writing code so that there is no room for misinterpretation. We can refer to the current instance of a class with the this keyword.

class Forest { public int Area { /* property omitted */ } public Forest(int area) { this.Area = area; } }

this.Area = area means “when this constructor is used to make a new instance, use the argument area to set the value of this new instance’s Area field”.

We would call it the same way:

Forest f = new Forest(400);

f.Area now equals 400.

The word this might seem frustratingly vague. Think back to the “class is to instance as blueprint is to house” analogy. The class/blueprint has to use the generic this because the class/blueprint is going to be reused for every instance/house.



Specify the instance properties by using this.Name and this.Biome.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?