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

Problem with return type

Hi,

As I understood from course, if want to return value then I can indicate only "public GetNumFliesEaten()", but it asks for return type. What`s wrong?

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

        public GetNumFliesEaten()
        {
            return _numFliesEaten;
        }

        public void SetNumFliesEaten()
        {
            _numFliesEaten = value;
        }

    }
}

1 Answer

Steven Parker
Steven Parker
231,198 Points

The type of the value being returned (an int in this case) must be given between the word "public" and the method name.

Also, you'll need to declare the type and name of the parameter for your setter method.