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# C# Objects Object-Oriented Programming Initialization

Dennis Zern
Dennis Zern
813 Points

Easy! Help me with this challenge, explain why or specify where in the video that i should watch.

Easy! Help me with this challenge, explain why or specify where in the video that i should watch.

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;

    }
}
Dennis Zern
Dennis Zern
813 Points

Add a constructor to the Frog class that accepts a tongue length parameter value.

1 Answer

andren
andren
28,558 Points

Most of the previous video is dedicated to the topic of class constructors, so if you are confused it might be a good idea to just watch it over again from the start.

In the previous video Jeremy shows how to create a constructor for the Map class that takes a width and height parameter. The code required for this challenge is practically identical with the one shown. The only differences being in the names involved and the fact that in the challenge there is only one parameter (tongueLength) rather than two like there was with the Map constructor.

As a remainder the Map constructor ends up looking like this by the end of the video:

public Map(int width, int height) { // Take width and height as parameters
    Width = width; // Assign Width field to width parameter 
    Height = height; // Assign Height field to height parameter 
}

I added some commentary to clarify how it works, the Frog class constructor will end up looking pretty similar by the end of the challenge.