Equality Comparison with Multiple Instances/IEqualityComparer problems in LINQ
- by Stacey
This is similar to my last question; but from a different angle.
http://stackoverflow.com/questions/2792393/see-if-item-exists-once-in-enumerable-linq
Given the following set of items, and lists containing them...
Item 1
Item 2
Item 3
Item 4
Item 5
class Item
{
string Name { get; set; }
}
List<Item> available = new List<Item>()
{
Item 1
Item 1
Item 2
Item 3
Item 5
}
List<Item> selected = new List<Item>()
{
Item 1
Item 2
Item 3
}
I need to make a third List that has everything from "available", except what is in "selected".
However 'Item 1' is in 'available' twice, but only in 'selected' once. Since they are instances of the same item, I am having trouble figuring out the appropriate logic to accomodate this.
The final array should look like...
List<Item> selectable = new List<Item>()
{
Item 1
Item5
}