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 trial

C# C# Objects Encapsulation with Properties Properties

Challenge Task 1 of 1 Replace the accessor methods with a property named NumFliesEaten with a getter and setter for _nu

please help with "Bummer! Did you replace both accessor methods with a single property?"

I have no error messages when compiling, but need help, what I am I missing? Thanks!

Frog.cs
namespace Treehouse.CodeChallenges
{
    public class Frog
    {
        private int _numFliesEaten;

        public int GetNumFliesEaten()
    {
      return _numFliesEaten;
    }

    public void SetNumFliesEaten(int x)
    {
      _numFliesEaten = x;
    }
    }
}
Steven Parker
Steven Parker
231,248 Points

It doesn't look like you've changed anything other than the name of the setter argument.

Remember, the object here is to replace both the getter and setter methods with a new property which handles the private field.

You might want to review the Properties video, and watch how the Location property is constructed for the Invader class.

What I am I missing Parker??

namespace Treehouse.CodeChallenges { public class Frog { private int _numFliesEaten;

    public int NumFliesEaten
    {
        get
        {
            return _numFilesEaten;
        }
        set
        {
             _numFliesEaten = value;
        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,248 Points

:point_right: That's much better! Now you only have a typo.

You wrote "_numFilesEaten" instead of "_numFliesEaten".

Other than that, looking good! :+1:

Thank you!

namespace Treehouse.CodeChallenges { public class Frog { private int _numFliesEaten;

public int NumFliesEaten
{
    get
    {
        return _numFliesEaten;
    }
    set
    {
         _numFliesEaten = value;
    }
}

} }