Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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;
       }

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...