I want to remove objects from a list using linq,
for example :
public class Item
{
public string number;
public string supplier;
public string place;
}
Now i want to remove all of the items with the same number and supplier that appear more then once.
Thanks
This would be slightly tedious to do in-place, but if you don’t mind creating a new list, you can use LINQ.
The easiest way to specify your definition of item-equality is to project to an instance of an anonymous-type – the C# compiler adds a sensible equality-implementation on your behalf:
If my first guess was correct, you can also consider writing an
IEqualityComparer<Item>and then using theDistinctoperator:Btw, it’s not conventional for types to expose public fields (use properties) or for public members to have camel-case names (use pascal-case). This would be more idiomatic: