Louis Rhys Louis Rhys - 1 year ago 107
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download