reference a property value as comparer in ArrayList.BinarySearch

G

garyusenet

My Array list contains a collection of InternetExplorer object.

One of properties of this object is HWND.

I'm trying to search my arraylist for the InternetExplorer object that
has a certain value for its HWND property. But i don't know the syntax
to use.

I have tried many things, the latest I have tried is: -

ar.BinarySearch(InternetExplorer.HWND hwnd);

(ar is my arraylist, InternetExplorer is the type that all the objects
in my arraylist are, and hwnd is a class variable of type int, that
contains the HWND value i would like to locate in the array)

can someone suggest a fix please?

Thankyou,

Gary.
 
J

Jon Skeet [C# MVP]

My Array list contains a collection of InternetExplorer object.

One of properties of this object is HWND.

I'm trying to search my arraylist for the InternetExplorer object that
has a certain value for its HWND property. But i don't know the syntax
to use.

I have tried many things, the latest I have tried is: -

ar.BinarySearch(InternetExplorer.HWND hwnd);

(ar is my arraylist, InternetExplorer is the type that all the objects
in my arraylist are, and hwnd is a class variable of type int, that
contains the HWND value i would like to locate in the array)

can someone suggest a fix please?

You need to implement IComparer in a way that casts both sides to
InternetExplorer and returns the comparison of the HWND. Then pass an
instance of the class implementing IComparer into BinarySearch.

Note that the ArrayList has to be sorted (by your comparison criteria,
ie HWND in this case) before BinarySearch will work.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top