Learn

Congrats! You’ve finished a lot of content and some of the most important concepts in C#. When someone asks you, “How do I make a custom data type in C#?” you can talk all about it! In this lesson, you learned how to:

  • Define a class
  • Instantiate an object using new
  • Define fields, the pieces of data for each class
  • Define properties, the spokespeople for each field
  • Define automatic properties, the shorthand for making properties
  • Define methods, the actions a class can take
  • Define constructors, the special methods called when a class is instantiated
  • Overload constructors and reuse code with this
  • Control access to class members using public and private

Instructions

1.

Try out your complete Forest class in Main()!

  • Instantiate a new object with the name "Amazon". Store the result in a variable.
  • Print the Trees property to the console.
  • Call the Grow() method.
  • Print the Trees property again to the console to confirm that the Grow() method works.
Folder Icon

Take this course for free

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

Already have an account?