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 Method Overloading

C#

Can someone help me with the C# Objects, Method Overloading task?

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

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

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

2 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Christian,

Step 2 of the challenge wants you add the ability to provide a reaction time at the time the object is created by passing it to the constructor. The constructor method is Frog.

The constructor already has a parameter for tongue length, so to add a new parameter and assign the value passed in to our public read-only field looks like this.

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

        public Frog(int tongueLength, int newReadonlyField)
        {
            TongueLength = tongueLength;
            NewReadonlyField = newReadonlyField;
        }

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

I hope this helps.

Thanks!

Steven Parker
Steven Parker
230,248 Points

:point_right: For task 1, use the declaration of TongueLength as a sample.

Create another line like that but with the name the challenge says to use.

I forgot to mention that it is the second task I need help with. Can you give me a hint of the second task?