C# Querying With LINQ Query Operators Aggregates

Calvin Secrest
Calvin Secrest
22,167 Points

Confused about the syntax

Create a variable named sumOfSightings and assign it to the sum of all the Sightings in the ourBirds list. Bummer! Your code could not be compiled. Please click on "Preview" to view the compiler errors. Restart Preview Get Help Recheck work CodeChallenge.cs

CodeChallenge.cs
var myBirds = new List<Bird> 
{ 
    new Bird { Name = "Cardinal", Color = "Red", Sightings = 3 },
    new Bird { Name =  "Dove", Color = "White", Sightings = 2 },
    new Bird { Name =  "Robin", Color = "Red", Sightings = 5 }
};

var yourBirds = new List<Bird> 
{ 
    new Bird { Name =  "Dove", Color = "White", Sightings = 2 },
    new Bird { Name =  "Robin", Color = "Red", Sightings = 5 },
    new Bird { Name =  "Canary", Color = "Yellow", Sightings = 0 }
};

var ourBirds = myBirds.Join(yourBirds,
                            mb => mb.Name,
                            yb => yb.Name,
                            (mb, yb) => (mb));
var sumOfSightings.Sum( ourBirds => b.Sightings);

1 Answer

Steven Parker
Steven Parker
176,584 Points

:point_right: The assignment operator is "="

The instructions say "Create a variable ... and assign it", but you haven't used the assignment operator.

You also attached the Sum method to the variable you're creating, but the challenge asks for "the sum ... in the ourBirds list". And lastly, the lambda expression has a "b" on the right side, but not on the left.