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 trialAlexisca hall
23,683 PointsUse the private access modifier to make it so that classes other than Frog can get the value of NumFliesEaten but can’t
Use the private access modifier to make it so that classes other than Frog can get the value of NumFliesEaten but can’t set it.
namespace Treehouse.CodeChallenges
{
class Frog
{
private int _numFliesEaten;
public int NumFliesEaten{get;set;}
{
return _numFliesEaten;
}
public void SetNumFliesEaten( int numFliesEaten)
{
_numFliesEaten = numFliesEaten;
}
}
}
3 Answers
Steven Parker
231,269 PointsYou still haven't completely converted NumFliesEaten to an auto-property yet.
- all code will be moved to the get and set that belong to the property
- there won't be any external "getter" or "setter" functions anymore.
You might want to review the video on Auto-Properties.
Ashenafi Ashebo
15,021 PointsYour code should look like this one, but before that you to complete converting the NumFliesEaten to an auto-property
namespace Treehouse.CodeChallenges { public class Frog {
public int NumFliesEaten{ get; private set; }
}
}
Clive Machimbidza
4,163 Pointsi'm lost please help on this task....................Use the private access modifier to make it so that classes other than Frog can get the value of NumFliesEaten but can’t
Steven Parker
231,269 PointsIf you've done the first task correctly, for task 2 you just add the keyword "private" before "set".