Re: Visual C# Language ArrayList.IndexOf
IsshouFuuraibou
Because array list is generalized it compares the reference rather than performing the .Equals operation. ArrayList can technically have any object in it of any type, because each object is independant of the other objects you can have two items in ArrayList with different types
ArrayList a = new ArrayList();
a.Add( 42 );
a.Add( "Something" );
a.Add( new Vector3( 0, 1, 0 ) );
now how do you suppose
a.IndexOf( new Vector3( 0, 1, 0 ) );
is going to work with 42 with the string "Something"
In order to be able to call .Equals on all items in the list, it has to be able to understand all types of objects. How are you going to compate Vector3( 0, 1, 0 ) to "Something"
So, obviously it defaults to the object.Equals method which compares reference (location in memory)
since you're declaring a new Vector3 to find the one inside the list, your memory locations aren't going to be the same.
So the way you can get explicit compares is to use something that is typed. Since we now have (2.0+) generic collections, we can just form a typed collection with List<Type>. This will function like an ArrayList but maintain it's type information, and coincidentally call comparison operators from said type.