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
203,120 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.