为什么不调用重载方法呢?
我已经对类tt的Equals方法进行了重载,但是调试运行后发现它硬是不进重载方法,只调用了Object的Equals方法,为什么呢?
public class RequestQueue<T> { private LinkedList<T> items = new LinkedList<T>(); private int _count; public int Count { get { return this._count; } } public RequestQueue(int i) { this._count = i; } public void EnQueue(T item) { if (this.items.Count == this._count) { items.RemoveFirst(); items.AddLast(item); } else { items.AddLast(item); } } public int Test(T item) { return items.Count(s => s.Equals(item)); } } public class tt { public string Im { get; set; } public string UA { get; set; } public override bool Equals(object obj) { tt a = obj as tt; if (a.Im == this.Im && a.UA == this.UA) return true; return false; //return base.Equals(obj); } public override int GetHashCode() { return this.ToString().GetHashCode(); } }
protected void Page_Load(object sender, EventArgs e) { RequestQueue<tt> a = new RequestQueue<tt>(100); tt va = new tt() { Im = "1", UA = "2" }; tt vb = new tt() { Im = "1", UA = "3" }; tt vc = new tt() { Im = "1", UA = "2" }; Response.Write(a.Test(va)); }