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

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
592 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.