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

My constructor doesn't initialize the 'TongueLength' field to the value passed in?

Not sure where I'm going wrong here, part two of the challenge said my constructor was fine but in part three its wrong? Any help would be appreciated.

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

1 Answer

Steven Parker
Steven Parker
218,654 Points

Having a field and a parameter with the same name can be tricky. In the course examples, field names start with an upper-case letter and parameter names with a lower-case letter to make them distinct. You might want to do that here.

Otherwise, you'd need to put a "this." prefix in front of the field name to distinguish it from the parameter.