
olu adesina
Pro Student 19,018 Pointswhere does the g.key property come from in this example
when iterate through the List<> with the FROM and IN keywords we use a variable like b in birds to access properties of each object but there is no Key property in the bird object so where is the g.key property coming from
1 Answer

Steven Parker
177,847 PointsYou're right that a "bird" object doesn't have a "Key", but this is chained onto a GroupBy; and an IGrouping object (which the GroupBy creates) does have a Key. The key was selected by the function given to the GroupBy, so in this case it's the bird's "Color" value.
The "g" parameter name was probably chosen as a reminder that it represents an IGrouping object and not a bird.
olu adesina
Pro Student 19,018 Pointsolu adesina
Pro Student 19,018 Pointshow does c# know to assign g.key to the color property.
Steven Parker
177,847 PointsSteven Parker
177,847 PointsBirds.GroupBy(
b => b.Color
)
olu adesina
Pro Student 19,018 Pointsolu adesina
Pro Student 19,018 Pointsthank you kind sir