I'm creating a class that derives from List...
public class MyList : List<MyListItem> {}
I've overridden Equals of MyListItem...
public override bool Equals(object obj)
{
MyListItem li = obj as MyListItem;
return (ID == li.ID); // ID is a property of MyListItem
}
I would like to have an Equals method in the MyList object too which will compare each item in the list, calling Equals() on each MyListItem object.
It would be nice to simply call...
MyList l1 = new MyList() { new MyListItem(1), new MyListItem(2) };
MyList l2 = new MyList() { new MyListItem(1), new MyListItem(2) };
if (l1 == l2)
{
...
}
...and have the comparisons of the list done by value.
What's the best way...?