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 Object Initialization

Code challenge error

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

    Frog(int TongueLength)
    {

    }

}

}

Daniel Hildreth
Daniel Hildreth
16,170 Points

What is the problem you're trying to solve here?

Code challenge ask me to Add a constructor to the Frog class that accepts a tongue length parameter value.

3 Answers

Daniel Hildreth
Daniel Hildreth
16,170 Points

This is the syntax you're supposed to have.

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

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

You instantiate the tongueLength method variable and then assign it to the TongueLength instant variable declared at the top. Hope this helps you.

Daniel Hildreth
Daniel Hildreth
16,170 Points

Believe you need to instantiate it as such:

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

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

Are you able to send me a link to the challenge so I can see the question and how they set it up?