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 Accessor Methods

Amar Resic
Amar Resic
2,922 Points

Getter and Setter Coding Challenge Help

I didn't feel like there was enough info for this question. I tried so many different combinations and looked at the example. My error is saying did you set _numFliesEaten in the setter and return _numFliesEaten in the Getter. What value am I supposed to set _numFliesEaten to in the setter. Everything I try doesn't work.

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

            public int GetNumFliesEaten()
        {
            return _numFliesEaten;
        }
        public void SetNumFliesEaten(int _numFliesEaten)
        {

        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,198 Points

You're close, but there's a few issues yet:

  • the setter is missing the body code that would copy the argument into the field
  • the setter code will be easier to write if the parameter name is different from the field name