Reputation: 1047
This code generates errors as indicated:
Here is the error message:
The pop-up definition appears to indicate that the fields marked as undefined do exist:
What am I missing?
(Bonus points for telling me why some of error underlines in the code are red while others are blue.)
Upvotes: 0
Views: 231
Reputation: 156504
Remember that these are groups, so you've got two levels:
foreach(var g in groups)
foreach(var item in g)
Console.WriteLine(item);
When you do a "Group By" in LINQ, you end up with a series of actual "groups", each of which has a Key
and a series of values. This allows you to perform aggregate functions like Sum
, Min
or Max
on each grouping. If you just want the results with a similar CountryRegion
to end up together in a flattened collection, you may want to try OrderBy
instead.
Upvotes: 1
Reputation: 8488
You have an IQueryable<IGrouping<string,Anonymous>>
and therefore need to reference by Key.
foreach(var g in groups)
{
Console.WriteLine(g.Key.FirstName.Trim());
}
Upvotes: 3