C# C# Objects Loops and Final Touches Foreach Loops

olu adesina
PRO
olu adesina
Pro Student 19,018 Points

c# help!!! error CS0165: Use of unassigned local variable `totalTongueLength'

not sure where im going wrong here

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

            int totalTongueLength;

            foreach(Frog frog in frogs)
            {

                totalTongueLength += frog.TongueLength;

            }

            return totalTongueLength / frogs.Length;

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

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

2 Answers

olu adesina
olu adesina
Pro Student 19,018 Points

thank you that worked, but i was under the impression that when u declare a variable of type int its default value was 0

olu adesina
olu adesina
Pro Student 19,018 Points

thank you that worked, but i was under the impression that when u declare a variable of type int its default value was 0