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

How do you create a parameter within a method?

My code keeps popping up an error and I am unsure how to make a parameter within my method called distanceToFly.

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

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

        public bool EatFly ()
        {

         EatFly = distanceToFly < TongueLength;

         EatFly = !(distanceToFly > TongueLength);

         return EatFly;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,275 Points

A parameter is created by placing the declaration for it between the parentheses in the method definition.

For an example, see the definition of "Frog" above. It has a parameter named "tongueLength" of type "int".

Also, if you want to create a variable ("EatFly"), be sure to declare its type either before or while assigning it.

One more hint: the first assignment is overridden by the second one, so it can be removed entirely.