PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework
ArrayList.IndexOf(Object obj) functionality changed in .Net 2.0
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework
ArrayList.IndexOf(Object obj) functionality changed in .Net 2.0
![]() |
ArrayList.IndexOf(Object obj) functionality changed in .Net 2.0 |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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" <SailBoffin@discussions.microsoft.com> a écrit dans le message de news: A7F90D6C-5646-4383-9DBF-B4C76793C3E4@microsoft.com... > 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. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
SailBoffin <SailBoffin@discussions.microsoft.com> 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 - <skeet@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

