C# Querying With LINQ Query Operators Joins

This video was really confusing because you don't explain what a key is.

What is this "Key"? It looks like TKey is the same as when we used a dictionary. But why would Keys have anything to do with this because we aren't using a dictionary we are using lists and objects? Lists don't even have named items we could call a key.

2 Answers

Steven Parker
Steven Parker
173,991 Points

The "key" here isn't part of a data structure, but the field to be used in the "Join" operation to match with a similar field in the other data source.

Steven Parker
Steven Parker
173,991 Points

The items of a list are not fields, but if the list contains objects, then fields are part of those objects. In this case, the "birds" list contains objects, and each object contains a "Color" field. That's the first (or "outer") key.

Then "colors" is just a list of strings, so the item itself ("c -> c") is used as the second ("inner") key.

In both cases, the lambda returns the value to be used as the key when given the associated list item. This is needed because the "Join" arguments must be functions that return values and not the values themselves.

Can you explicate a little? What field? Fields are part of objects. I don't know if the items of a list are fields though. And as far as I can tell we are matching on values rather than variables. And what does this lambda have to do with a key/field?

Steven Parker
Steven Parker
173,991 Points

See the comment I added to my answer.