Alex Rivera | Logout

Add items to a collection if the collection does NOT already contain it by comparing a property of the items?

Asked 2011-06-13T13:38:47.433
61

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?
Edit
Report

1 Answer

0
var newItems = DownloadedItems.Where(i => !CurrentCollection.Any(c => c.Attr == i.Attr));
answered 2011-06-13T13:42:57.607

Your Answer