Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,083 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
216,083 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;
    }
}

} }