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

Hermes Crespo
Hermes Crespo
980 Points

I am doing exactly what the challenge is asking me to do which is to use the constructor to initialize the field ...

... TongueLength. So why am I getting the feedback "Bummer! Does your constructor..."???

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

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

3 Answers

Hey Hermes! As steven pointed out, the field and the arguement for the constructor could be called two different things, in order for you to pass this challenge. Because of the concept of scope your currently just saying that the arguement in the constructor should be equal to the arguement, but you should be setting the actual field.

Another way to do this is to use the 'this' keyword:

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

        public Frog(int TongueLength)
        {
            this.TongueLength = TongueLength; // this.TongueLength is talking about the field TongueLength.
        }
    }
}

Hope this helps!

Hermes Crespo
Hermes Crespo
980 Points

Thanks a million !! :)

Steven Parker
Steven Parker
218,639 Points

That might work, but it's a different practice than what is shown in the course examples.

Hermes Crespo
Hermes Crespo
980 Points

Thanks everyone. I will try the "this" thing.... but... how was I supposed to know that if the session did not covered that concept??

Steven Parker
Steven Parker
218,639 Points

I suggest changing the argument name instead. That would make it like the examples that were shown in the video.

Levente Bito
Levente Bito
4,679 Points

There is some kind of issue here, because even though I answer correctly or using the this method, I get the error. This isn't the first issue here, I've had the same issue with the previous challenge. There something wrong with the program/website.....

Hey Levnte! I seriously doubt that mate, try posting your code here so we can spot your typo ;)

That being said if you really do belive you have discovered a bug, you should contact staff directly.