I have an amount of items in a list or list_1
. Each item is a row from a database. An import of these items is going to happen on another list, or list_2
. list_2
already contains content of the same type.
Is there a way to make this happen so that only those items that are not present in list_2
get imported?
Note that the original order must be retained in list_2
and the new items are to be imported on top of that original order. The order is important because list_2
actually is a concurrentqueue. So, the content of list_1
should be updated somehow (clearing the duplicates) before I can start importing it into list_2
. The actual import into list_2
(queue) is not a problem, it's the way to clean up list_1
that interests me. Thanks.
using System.Linq;
//...
var strippedList1 = list_1.Except(list_2);
To make this work, you need to make sure that your objects implement Equals
/ GetHashcode
please look at my below code it may help you
List<string> l = new List<string>();
l.Add("1");
l.Add("2");
List<string> l1 = new List<string>();
l1.Add("1");
var abc = l.Except(l1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.