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 trialGabriel Lehbert
3,969 PointsNeed help with C# Constructers! Assistance is highly appreciated.
Here is my code. For whatever reason I can't click "Get Help" so I'll do it this way. namespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength; public readonly int ReactionTime;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
2 Answers
Steven Parker
231,236 PointsTake a look at what the constructor has now:
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
There is one parameter in the constructor named tongueLength and it uses it to initialize the value of the TongueLength field. Notice that the parameter name starts with a lower case letter, but the field name has an upper case letter.
Your job is to edit the constructor so it takes two parameters. The second parameter will go beside the first, separated by a comma. Then you will add another line to do the initialization, much like the one already there but with different names. The challenge gave you the name to use for the parameter, and the name of the field that it initializes. The only thing missing is the type of the parameter, but you guess that will be int to match the type of the field.
I'll bet you can get it now, right?
Gabriel Lehbert
3,969 PointsThanks, I totally get it. You are awesome.
Gabriel Lehbert
3,969 PointsSteven Parker Hey! Thanks for replying. The question that I need help with is this: "Add a second parameter to the constructor named reactionTime after the existing parameter and use it to initialize the value of the ReactionTime field." I don't get it? Thanks again, you are awesome.
Steven Parker
231,236 PointsSteven Parker
231,236 PointsThe constructor above looks good. What problem are you having?
Also, use the Markdown Cheatsheet info for code formatting.