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

Heather Barton
Heather Barton
658 Points

else/if statements

I'm not sure what I'm doing wrong here - the compiler seems to be telling me that I'm using a '=' when I shouldn't be. Am I using 'return' in the wrong way?

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

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

            if (tongueLength >= distanceToFly)
            {
                return = true;
            }
            else
            {
                return = false;
            }
        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,269 Points

It sounds like you already figured part of it out — there's no "=" in a "return" statement. Also:

  • the "tongueLength" was a constructor parameter. You don't have (or need) access to it in this function
  • the "TongueLength" you want to compare with is the one with capital "T"
Heather Barton
Heather Barton
658 Points

got rid of the '=' and made "tongueLength" and internal variable and that worked, thank you!

Steven Parker
Steven Parker
231,269 Points

Heather Barton — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!

Steven Parker
Steven Parker
231,269 Points

I'm not sure what you mean by made "tongueLength" and internal variable. The lower-case-"t" variable is only used as a constructor parameter, you don't need it again. And this line from the constructor does not need to be in the other function at all:

            TongueLength = tongueLength;