Distinct on multiple properties in a collection

Problem:
How do I get distinct members of a collection, based on multiple properties?

Solution:
Use MoreLinq to get distinct members of a collection, based on multiple properties.
eg: For our application, each member in the household was supposed to have a unique combination of driver’s licence number and driver’s state.

 
var query = household.DistinctBy(
            counter => new { counter.DriverLicenceNumber, counter.DriverLicenceState });

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.