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 Loops and Final Touches Foreach Loops

foreach loop challenge: i don't understand the conditional statement

in the conditional statement what is the 3 "frog" for me the first "Frog" is the class the second ("frog") act as a counter the third it the object of the class

why "frogs.TongueLength" do not work but "frog.TongueLength" will work

FrogStats.cs
namespace Treehouse.CodeChallenges
{
    class FrogStats
    {
        public static double GetAverageTongueLength(Frog[] frogs)
        {
            double average = 0.0;

            foreach(Frog frog in frogs)
            {
                average = frogs.TongueLength;
            }

            return average/frogs.Lenght;
        }
    }
}
Frog.cs
namespace Treehouse.CodeChallenges
{
    public class Frog
    {
        public int TongueLength { get; }

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

2 Answers

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

frog is a variable of type Frog, which is a class that has a TongueLength property.

frogs is a variable of type Frog[], a list of frogs. Lists don't have TongueLength, individual frogs in the list do.

Try iterating through all the lists and calculating a sum of tongue lengths, and then dividing that sum by the number of frogs in the list.

hey Brendan are you on social media? if yes what your handle?