How to write this nested foreach loop query in LINQ?

It should be something like this (Use SelectMany and Count methods):

int c = elements.SelectMany(e => e.Attributes)
                .Count(a => a.Name == "City" && a.GetValue().ToString() == "Oakland");

Leave a Comment