RobertKing
RobertKing

Reputation: 1911

linq query to get different records from two lists

i'm having two lists(list1 & list2) and want to get only the records in list1 that are not in list2.

How can i achieve this using LINQ expression in C#

Upvotes: 0

Views: 715

Answers (1)

gzaxx
gzaxx

Reputation: 17590

If both list contains comparable objects then this will do the job:

var newlist = list1.Except(list2);

otherwise you may need to use custom IEqualityComparer to get desired results:

var newlist = list1.Except(list2, new YourCustomComparer());

Upvotes: 2

Related Questions