KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I overrode the Equals() of my class to compare ID values of type Guid. Then Visual Studio warned: ... overrides Object.Equals(object o) but does not override Object.GetHashCode() So I then also overrode its GetHashCode() like this: public partial class SomeClass { public override bool Equals(Object obj) { //Check for null and compare run-time types. if (obj == null || this.GetType() != obj.GetType()) return false; return this.Id == ((SomeClass)obj).Id; } public override int GetHashCode() { return this.Id.GetHashCode(); } } It seems to work. Have I done this correctly? Remember Id is of type Guid. Does it matter that my class is an Entity Framework object?
Tags (comma-separated)
Save Edits
Cancel