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 trialLi Yu
2,067 PointsC# return type
What is wrong with my return type?
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
public readonly int ReactionTime;
public Frog2(int reactionTime)
{
ReactionTime = reactionTime;
return reactionTime;
}
//This is the error" Class, struct, or interface method must have a return type"
}
}
2 Answers
William Li
Courses Plus Student 26,868 PointsI guess you're in part 1 of the challenge, no?
Add another public readonly integer field to the Frog class named ReactionTime.
It asked you to add a new field to Frog class, it appears that you wrote the code inside the Frog method, which is wrong here.
Where to put the new field? It should be placed under this line public readonly int TongueLength;
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int ReactionTime; // add the ReactionTime field
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
hope it helps.
Manala Jubane
788 Pointsnamespace 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;
}
}
}
Li Yu
2,067 PointsLi Yu
2,067 PointsIt works, thanks William.