fguihen Posted March 15, 2005 Posted March 15, 2005 i have a cartesian point. i want to insert it into an arrayList of cartesian points. before i insert it, i want to make sure it doesnt already exist. how would you go about this? Quote
mskeel Posted March 15, 2005 Posted March 15, 2005 The easy way would be to search the list until you find the point then return true, meaning you found it. to psuedo it out... bool Exists(newPoint) { for each point in someList { if point == newPoint { return true //found the point, no need to keep looking, don't add it. } } return false //searched entire list, didn't find it, add it. } I believe there might also be an exists method in arrayList (I could be wrong) but I think that will only compare memory locations, not wether the two points are, value-wise, equal...it will only compare the references or pointers, not the values, or dereferenced pointers. That's probably more confusing than it needs to be.... Quote
*Experts* DiverDan Posted March 15, 2005 *Experts* Posted March 15, 2005 Not knowing everything about the ArrayList structure you might also try: Dim sample As New ArrayList() If sample.Contains('blah) Then 'some action Else 'some other action End If Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
mskeel Posted March 15, 2005 Posted March 15, 2005 contains, that's what I was thinking. Not exists. Won't that only compare the references and not the values of the objects, though? Unless the objects are primitives? Except they aren't called primitives in .Net, their called...base types? (string, intiger, float, etc...) Quote
*Experts* DiverDan Posted March 15, 2005 *Experts* Posted March 15, 2005 That's why I prefaced my post with "Not knowing everything about the ArrayList structure" If the ArrayList stores a list of points in the {X, Y} format then comparing a new point in the same format with .Contains works fine. Otherwise your method is required. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
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.