Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add elements from one collection that do not exist in a second collection to a third collection?

Tags:

c#

linq

I have 3 generic lists:

List<string> input
List<string> compareTo
List<string> results

I'd like to take the list of input and compare each value to the compare list, and if it doesn't exist add it to the results list.

like image 709
Rod Avatar asked Jan 05 '12 20:01

Rod


1 Answers

Any reason you can't just use LINQ?

List<string> results = input.Except(compareTo).ToList();
like image 69
Jon Skeet Avatar answered Oct 22 '22 10:10

Jon Skeet