Why would you particularly want to include the type in the hashcode? I can see how that could be useful if you had a lot of different types of object with the same ID in the same map, but normally I'd just use
public override int GetHashCode()
{
return ID; // If ID is an int
// return ID.GetHashCode(); // otherwise
}
Note that ideas of equality become tricky within inheritance hierarchies - another reason to prefer composition over inheritance. Do you actually need to worry about this? If you can seal your class, it will make the equality test easier as you only need to write:
public override bool Equals(object obj)
{
MyType other = obj as other;
return other != null && other.ID == ID;
}
(You may well want to have a strongly-typed Equals method and implement IEquatable.)