[ACCEPTED]-Linq: What is the difference between == and equals in a join?-equals
There's a nice explanation by Matt Warren 21 at The Moth:
"The reason C# has the word ‘equals’ instead 20 of the ‘==’ operator was to make it clear 19 that the ‘on’ clause needs you to supply 18 two separate expressions that are compared 17 for equality not a single predicate expression. The 16 from-join pattern maps to the Enumerable.Join() standard 15 query operator that specifies two separate 14 delegates that are used to compute values 13 that can then be compared. It needs them 12 as separate delegates in order to build 11 a lookup table with one and probe into the 10 lookup table with the other. A full query 9 processor like SQL is free to examine a 8 single predicate expression and choose how 7 it is going to process it. Yet, to make 6 LINQ operate similar to SQL would require 5 that the join condition be always specified 4 as an expression tree, a significant overhead 3 for the simple in-memory object case."
However, this 2 concerns
join. I'm not sure
equals should be used 1 in your code example (does it even compile?).
Your first version doesn't compile. You 2 only use
equals in joins, to make the separate halves 1 of the equijoin clear to the compiler.
More Related questions