fguihen Posted March 22, 2005 Posted March 22, 2005 i have an arraylist of a vector object that i creted myself. I am adding new vectors to this list, but i want to check if they are in the list already. they are supposed to be compared on the x and y co-ordinates of the vector. if i override the Equals method of the vector class , as shown below, will i be able to use the arraylist.Contains to see if the arraylist contains the vector about to be put into it? public override bool Equals(object obj) { //return base.Equals (obj); Vector v = (Vector)obj; if(this.Xval == v.Xval && this.Yval == v.Yval) { return true; } return false; } Quote
HJB417 Posted March 22, 2005 Posted March 22, 2005 yes ripped from the msdn documentation This method performs a linear search; therefore, the average execution time is proportional to Count. That is, this method is an O(n) operation, where n is Count. This method determines equality by calling Object.Equals. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.