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
MOD
Brendan Whiting
Front End Web Development Treehouse Moderator 84,129 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?