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

Thomas Newton
PLUS
Thomas Newton
Courses Plus Student 2,442 Points

Use the constructor to initialize the TongueLength field to the value passed in.

I... have literally no idea what any of this means. Nothing in the previous video said what initializing was or explained how I would do this. Could somebody fill me in on what to do?

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

      public Frog( int TongueLength){

        TongueLength = TongueLength;

      }
    }
}

2 Answers

Chris M
Chris M
591 Points

I solved it by doing this

namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        public Frog (int tongueLength)
    {
        TongueLength = tongueLength;

    }
  }
}

you forgot to put some stuff in small caps.

change

 public Frog( int TongueLength){

to

 public Frog( int tongueLength){

and

TongueLength = TongueLength;

to

TongueLength = tongueLength;

You're using the "tongueLength" to initialize the TongueLength field. Don't feel too bad, you had the basic idea down.

You probably figured it out, but for whoever comes here later:

"Use the constructor to initialize the TongueLength field to the value passed in" is a poor way to word the question. Basically, the question is telling you to use the constructor you just build in the previous phase to automatically set a length without one being instantiated.

Simply change the line public Frog (int tongueLength) to public Frog (int tongueLength = X) where X is an integer.