See if item exists once in Enumerable (Linq)

Posted by Stacey on Stack Overflow See other posts from Stack Overflow or by Stacey
Published on 2010-05-08T00:14:49Z Indexed on 2010/05/08 0:18 UTC
Read the original article Hit count: 243

Filed under:
|

Given a list...

class Item
{
 public Name
 {
   get;
   set;
 }
}

List<Item> items = new List<Item>
{
 new Item() { Name = "Item 1" },
 new Item() { Name = "Item 1" },
 new Item() { Name = "Item 2" },
 new Item() { Name = "Item 3" }
}

List<Item> listing = new List<Item>
{
 new Item() { Name = "Item 1" },
 new Item() { Name = "Item 2" },
 new Item() { Name = "Item 3" }
 new Item() { Name = "Item 4" }
}

etc.

I need to create a third array that will cancel out double instances between the two; however items with "Name 1" are both the same, but different 'instances'. So the third List should have 1 instance of Item 1, since 'items' had 2 instances. Any ideas of how this can be done through Linq?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ