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

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!