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

Idan shami
Idan shami
13,251 Points

please help

I don't understand how to create distancetofly as parameter

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
        public bool EatFly(DistanceToFly distanceToFly)
        {
          bool CanEat =  distanceToFly <= tongueLength; 
        }
    }
}

2 Answers

Raffael Dettling
Raffael Dettling
32,998 Points

You got the question wrong only return true or false in the eat fly function and distanceToFly is from type int. And you have to change tongueLength to TongueLength because tongueLength is only available inside the Frog function itΒ΄s his parameter.

 public bool EatFly(int distanceToFly)
        {
          return distanceToFly <= TongueLength; 
        }

In the EatFly function you have declared a vaiable but you haven`t return a bool value. To return a bool value type one of these blocks in the function body(Actually they are pretty mush the same): 1-

          <p>bool CanEat =  distanceToFly <= tongueLength; 
                 return CanEat;</p>

2-

          <p>return distanceToFly <= tongueLength; </p>

Additional notes: According to the coding convention followed in the C# programming language or the .Net generally : method variables should start with a lower-case letter for the first word and any other words should start with upper-case letter