I am trying to find the intersection between two lists using the Linq Intersect method and a custom equality provider.
The lists contain objects (representing a file system file) and contain relative and absolute paths. I have defined a IEqualityComparer class to declare two files as equal if they have the same relative path.
I now would like to specify in the Intersect method that the match with more recent modify date is the one to keep in the resulting intersection list.
What is the best way to do this? Can I modify the IEqualityComparer to do this?
No, you’re not understanding it correctly.
Intersectmeans that the objects are equal and just after you say “oh no they are not equal”. Intersect is not the function you want. You want something likeGroupByinstead. LeaveIntersectalone until you really need an intersection.