public abstract class IdenticalObject { public IdenticalObject(string id) { this.ID = id; } public string ID { get; private set; } public static bool operator ==(IdenticalObject obj1, IdenticalObject obj2) { return obj1.ID == obj2.ID; } public static bool operator !=(IdenticalObject obj1, IdenticalObject obj2) { return obj1.ID != obj2.ID; } public override bool Equals(object obj) { return this.Equals(obj); } public override int GetHashCode() { return base.GetHashCode(); } }
继承此类,就可以实现了