473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

reference a property value as comparer in ArrayList.BinarySearch

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
1 1871
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Homa | last post by:
I can' believe my own eye, but it happens...there is a bug in ArrayList.BinarySearch!! It should be such a simple function...... Here is the detail. (I'm using C#, don't know if this is C#'s...
5
by: Steve | last post by:
newbie question. In C++ I could get a pointer to an item in a list, for example int* pInt = &myList; then I could do something like: *pInt = 666; and then myList would equal 666. Nice,...
3
by: MattC | last post by:
Hi, I found this code somewhere on the net and need to make some alterations. public class GenericSorter : IComparer { String sortProperty; bool sortOrder; public GenericSorter(String...
3
by: Bradley | last post by:
Hi I have an ArrayList populated with some objects. Each object has some properties, and I'd like to find the ArrayList's index where the object's "SerialNumber" property is equal to a certain...
2
by: Martin Ortiz | last post by:
Ugh.... All classes are copy by reference, even if you use "ByVal" and NOT "ByRef" it's still a copy by reference. Of course, as a consequence, if you change any values of the object you passed...
2
by: Henry Padilla | last post by:
I have a list of strings and I would like to insert them in order as they come up. I am trying to use ArrayList.BinarySearch which (theoretically) returns the negative bitwise compliment. And I...
10
by: JohnR | last post by:
I have an arraylist of string values. I would like to search the arraylist to find the index of a particular string and I would like the search to be case insensitive. dim al as new arraylist...
6
by: John Veldthuis | last post by:
I have an ArrayList set up with a set of class objects. The class has 3 strings in it and are as follows ProdID GSP Description Okay now problem with getting all these into the list and...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.