I have a list
List<MyObject> myList
and I am adding items to a list and I want to check if that object is already in the list.
so before I do this:
myList.Add(nextObject);
I want to see if nextObject is already in the list.
The object "MyObject" has a number of properties but comparison is based on matching on two properties.
What is the best way to do a check before I add a new "MyObject" to this list of "MyObject"s.
The only solution I thought up was to change from a list to a dictionary and then make the key a concatenated string of the properties (this seems a little unelegant).
Any other cleaner solutions using list or LINQ or something else?