By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,635 Members | 1,699 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,635 IT Pros & Developers. It's quick & easy.

reference a property value as comparer in ArrayList.BinarySearch

P: n/a
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.

Dec 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ga********@myway.com wrote:
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

Dec 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.