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

Sarah Newton
Sarah Newton
2,179 Points

Cannot understand what I am required to do to generate the return value in the task.

The task felt unclear as to how to go about getting the return value. Not sure if I need to initialize an instance of tongueLength and assign it a value and then calculate a boolean return value based upon the distance value being less than tongueLength.

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }

        public bool EatFly(int distanceToFly)
        {
            bool canReachFly = distanceToFly < Frog.tongueLength;
            return canReachFly;
        }
    }
}

2 Answers

If you click preview you'll see

error CS0117: `Treehouse.CodeChallenges.Frog' does not contain a definition for 'tongueLength'

but it does have a definition for TongueLength. So if you change

bool canReachFly = distanceToFly < Frog.tongueLength;

to

bool canReachFly = distanceToFly < Frog.TongueLength;

you'll see error CS0120: An object reference is required to access non-static member `Treehouse.CodeChallenges.Frog.TongueLength'

If you then change to

bool canReachFly = distanceToFly < this.TongueLength;

or just

bool canReachFly = distanceToFly < TongueLength;

you'll pass

Sarah Newton
Sarah Newton
2,179 Points

Perfect answer, thanks!