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

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
231,198 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.