KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a strongly typed list of custom objects, MyObject , which has a property Id , along with some other properties. Let's say that the Id of a MyObject defines it as unique and I want to check if my collection doesn't already have a MyObject object that has an Id of 1 before I add my new MyObject to the collection. I want to use if(!List<MyObject>.Contains(myObj)) , but how do I enforce the fact that only one or two properties of MyObject define it as unique? I can use IComparable ? Or do I only have to override an Equals method? If so, I'd need to inherit something first, is that right?
Tags (comma-separated)
Save Edits
Cancel