I'm working on a simple application with a few classes. This all started when I wanted to use the Remove
method on a List<Car>
. This method requires that you override the Equals
and the GetHashCode
methods for the Car
type. In this situation, I decided to implement an ID property on the Car
class. That way, my Equals
method simply checks for ID equality, and my GetHashCode
method returns base.GetHashCode()
.
Is this a good approach, or is implementing a GUID for a small class too heavy-handed? There wouldn't be any need for it without the reasons I explained above. The only requirement for uniqueness for this Car type is that it be unique within the List<T>
collection to which it belongs. But adding the GUID property seemed like the quickest way around the GetHashCode
mess. BTW, there are no int properties on my Car type.