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 trialJustin Ramirez
4,915 PointsNeed help understanding this problem " Use the constructor to initialize the TongueLength field to the value passed in."
I don't understand what it means when it says " value passed in?"
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog (int TongueLength)
{
int TongueLength = TongueLength;
}
}
}
1 Answer
Ted Dunn
43,783 PointsThe value passed in is the argument TongueLength which is the variable inside the parentheses of the Frog constructor. Your code will not pass because you need to set the field of TongueLength which was declared outside of the constructor (public readonly int TongueLength) to the value of the TongueLength which was supplied as the argument in the constructor (public Frog(int TongueLength).
You need to invoke the keyword 'this' on the field and set it equal to the argument.
public Frog(int TongueLength)
{
this.TongueLength = TongueLength;
}
Justin Ramirez
4,915 PointsJustin Ramirez
4,915 PointsThank you very much for your help the code did work.
Grigor Samvelian
2,852 PointsGrigor Samvelian
2,852 PointsDidn't learn anything about the keyword this before the challenge, it was the correct answer but i'm having trouble understanding the purpose of the keyword this, if anyone could elaborate on how it help solve this challenge it would be appreciated and great.