Louis Rhys Louis Rhys - 1 month ago 12
C# Question

Can I use Linq's Except() with a lambda expression comparer?

I know I can call linq's Except and specify a custom IEqualityComparer, but implementing a new Comparer class for each data type seems like an overkill for this purpose. Can I use a lambda expression to provide the equality function, like when I use Where or other LINQ functions?

If I can't, is there an alternative?


I don't think you can directly with the basic LINQ interfaces, but I've seen people implement a LambdaComparer class with extension methods which will help you do it.

Here's an example