Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Object-Oriented Programming Initialization

Andrew Galle
Andrew Galle
4,025 Points

I think I don't understand this question:

What does this mean? What does it want me to do? Isn't the value already initialized to the value passed in because the constructor sets tongueLength to TongueLength?

Thank you for your help!

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

        public Frog(int tongueLength)
        {
            tongueLength=TongueLength; 
        }
    }
}

2 Answers

This challenge wants you to use the constructor to set the value of TongueLength in the class to the value that was passed in the constructor. You are close with the way you have done it, but you have the variables the wrong way around. You have set the variable that was passed to the constructor to the class variable instead of setting the class variable to the variable passed to the constructor.

It should look like this:

    class Frog
    {
        public readonly int TongueLength;

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
    }
Andrew Galle
Andrew Galle
4,025 Points

Oh, I get it. Thank you so much!