Basically, how do I make it so I can do something similar to: CurrentCollection.Contains(...), except by comparing if the item’s property is already in the collection?
public class Foo
{
public Int32 bar;
}
ICollection<Foo> CurrentCollection;
ICollection<Foo> DownloadedItems;
//LINQ: Add any downloaded items where the bar Foo.bar is not already in the collection?
You start by finding which elements are not already in the collection:
And then just add them:
Note that the first operation may have quadratic complexity if the size of
DownloadedItemsis close to the size ofCurrentCollection. If that ends up causing problems (measure first!), you can use aHashSetto bring the complexity down to linear: