Suppose I have a simple DTO object right out of the database, and the Id is a recordId that is definitely unique, is it a good idea then to do the following ?
public class DTO
{
public int Id { get; set; }
public override bool Equals(object obj)
{
return (Id == ((DTO)obj).Id);
}
public override int GetHashCode()
{
return Id;
}
}
The reason I doubt it a bit is because I don't see it in code around me, as oposed to code like
int hash = 7;
hash = 89 * hash + pageId.hashCode();
hash = 89 * hash + recordId;
return hash;