PC Review


Reply
Thread Tools Rate Thread

ArrayList.IndexOf(Object obj) functionality changed in .Net 2.0

 
 
=?Utf-8?B?U2FpbEJvZmZpbg==?=
Guest
Posts: n/a
 
      4th Apr 2006
Has anyone else noticed a change in this function with .Net 2.0?

The help says it uses the Object.Equals method to do a linear search of the
ArrayList. In .Net 1.1, it used the Object.Equals override of the argument
to the method, in .Net 2.0 it uses the Object.Equals override of the elements
of the array. It's a subtle change but was more useful before. As it stands
now, one override of Object.Equals is used for all searches whereas before
you could create a new search object if you wanted to search on a different
parameter. It's simliar to what we used to do with predicate
objects/functions in STL.
 
Reply With Quote
 
 
 
 
Bruno Jouhier
Guest
Posts: n/a
 
      4th Apr 2006
Your Equals override should conform to the semantics of Equals. In
particular, it should be symmetric:

o1.Equals(o2) == o2.Equals(o1) when o1 and o2 are not null.

If you follow this rule, you should get the same result with the 1.1 and 2.0
versions.

It looks like you are distorting the semantics of Equals and relying on
special undocumented characteristics of the framework implementation. Then
you are on your own, and you have to be ready for some surprises when the
framework evolves.

Bruno.


"SailBoffin" <(E-Mail Removed)> a écrit dans le message
de news: A7F90D6C-5646-4383-9DBF-(E-Mail Removed)...
> Has anyone else noticed a change in this function with .Net 2.0?
>
> The help says it uses the Object.Equals method to do a linear search of
> the
> ArrayList. In .Net 1.1, it used the Object.Equals override of the
> argument
> to the method, in .Net 2.0 it uses the Object.Equals override of the
> elements
> of the array. It's a subtle change but was more useful before. As it
> stands
> now, one override of Object.Equals is used for all searches whereas before
> you could create a new search object if you wanted to search on a
> different
> parameter. It's simliar to what we used to do with predicate
> objects/functions in STL.



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      6th Apr 2006
SailBoffin <(E-Mail Removed)> wrote:
> Has anyone else noticed a change in this function with .Net 2.0?
>
> The help says it uses the Object.Equals method to do a linear search of the
> ArrayList. In .Net 1.1, it used the Object.Equals override of the argument
> to the method, in .Net 2.0 it uses the Object.Equals override of the elements
> of the array. It's a subtle change but was more useful before. As it stands
> now, one override of Object.Equals is used for all searches whereas before
> you could create a new search object if you wanted to search on a different
> parameter. It's simliar to what we used to do with predicate
> objects/functions in STL.


Unfortunately, ArrayList makes this tricky - but List<T> has FindIndex
which takes a Predicate delegate, which is the right way of doing this.
As Bruno says, Object.Equals should be consistent so that the result is
the same either way.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arraylist IndexOf Structure ray@Mississauga.Canada Microsoft ASP .NET 0 18th Feb 2010 04:15 PM
ArrayList and indexOf tony Microsoft C# .NET 2 23rd Aug 2006 09:19 PM
ArrayList.IndexOf method Qubeczek Microsoft Dot NET Compact Framework 0 17th Jun 2006 02:09 PM
Case insensitive Arraylist.indexof search JohnR Microsoft VB .NET 10 12th Oct 2005 04:06 PM
ArrayList.indexOf(self-defined class) paulyip Microsoft C# .NET 1 21st Jan 2005 07:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:16 AM.