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 trialNick Torchio
912 PointsOO Code Challenge
I keep getting a hint that says "Does your constructor initialize the 'TongueLength' field to the value passed in?"
I don't think I understand what field and what value this is referring to. I've reviewed the video a few times but I still can't figure out what's missing.
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int TongueLength)
{
TongueLength = 5;
}
}
}
2 Answers
Steven Parker
231,198 PointsHere's a few hints:
- the field is named TongueLength (it's what you made readonly in task 1)
- the value to set it with is passed in to the constructor for Frog
- you currently have the constructor argument also named TongueLength but that makes things complicated
- the convention in the course is to name the argument like the field, but with a lower-case first letter
- you should set the TongueLength using the passed argument, instead of the fixed value 5
Henrique Vignon
Courses Plus Student 6,415 PointsYou shouldn't set a fixed value for the field inside the constructor, that's what the argument is there for, plus the argument cannot have the same name as the field.
Steven Parker
231,198 PointsActually, the argument can have the same name as the field, but then to access the field you have to prefix it with "this.", and reusing the name is considered bad practice.
Henrique Vignon
Courses Plus Student 6,415 PointsEh, sounds like more work than it's worth :P, but good to know, I was not aware of that.
Nick Torchio
912 PointsBut what is the "field" and where is the value supposed to be "passed in" to?