直接上码:
public class MyObject { public string name; public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != this.GetType()) return false; return ((MyObject)obj).name == this.name; } public override int GetHashCode() { return (name != null ? name.GetHashCode() : 0); } }
时间: 2024-10-07 06:39:33