What could be wrong with this class? Think carefully and post your answer in the comments.
class Something { public string ServiceName { get; private set; } public int DbId { get; private set; } public Something(string serviceName, int dbId) { if (serviceName == null) throw new ArgumentNullException("serviceName"); ServiceName = serviceName; DbId = dbId; } public override int GetHashCode() { return ServiceName.GetHashCode() + DbId; } public override bool Equals(object obj) { Something other = obj as Something; return other != null && DbId == other.DbId && ServiceName == other.ServiceName; } }
Having made that mistake … possibility of overflow in GetHashCode().
Hey, was this adapted from my code? 🙂