Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,696 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?