473,324 Members | 2,417 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,324 software developers and data experts.

Get an Object according to its index in ArrayList

Hi,

I declare PageObjectsArray1 and PageObjectsArray2 as ArrayList. Each
element in the array is a Page object. Now I want to compare every pair
of Page objects of the same index in the two arrays.

However, it seems that there is no method in ArrayList such as
"GetAt(i)" so that I can return a Page object at a particular location
in the array. Could anyone help me to find out there is such method or
an alternative?

FYI, I have:

foreach (Page p1 in PageObjectsArray1)
{
//I want to get a Page object with the same index for
PageObjectsArray2 so that I can compare the two pages.
}

Many thanks!

May 16 '06 #1
4 1227
Hello, Fir5tSight,

Perhaps you are looking for the "IndexOf" method. E.g.

PageObjectsArray2.Item(PageObjectsArray1.IndexOf(p 1))

But wouldn't it be easier to just iterate through the indices of the
ArrayList?

Eg.

For ItemNumber As Integer = 0 To PageObjectsArray1.Count - 1
' Comparisons, etc.
Next ItemNumber

If you do elect to use the IndexOf method, note that it returns the
index of the first matching entry in the array list. For your stated
purpose this probably doesn't matter, but for some applications it
could. You can use other overloads of IndexOf to get around this if it
is a problem.

Cheers,
Randy
Fir5tSight wrote:
Hi,

I declare PageObjectsArray1 and PageObjectsArray2 as ArrayList. Each
element in the array is a Page object. Now I want to compare every pair
of Page objects of the same index in the two arrays.

However, it seems that there is no method in ArrayList such as
"GetAt(i)" so that I can return a Page object at a particular location
in the array. Could anyone help me to find out there is such method or
an alternative?

FYI, I have:

foreach (Page p1 in PageObjectsArray1)
{
//I want to get a Page object with the same index for
PageObjectsArray2 so that I can compare the two pages.
}

Many thanks!

May 16 '06 #2
for (int i=0;i<PageObjectsArray1.Legnth;i++){
if (i<PageObjectsArray2.Length) {
comparison =
PageObjectsArray1[i].Equals(PageObjectsArray2[i]);
}
}

May 16 '06 #3
Hi Tasos,

Many thanks for the suggestion! This is exactly what I needed. Thanks
again.

May 19 '06 #4
Hi Randy,

The issue was that I needed to get the element in a certain position in
an ArrayList. Tasos gave me the answer I was looking for. Thanks for
the help though!

May 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tamir Khason | last post by:
How can I set the type of the object added to ArrayList (type of Array List Members) Here is the code: protected ArrayList tabs = new ArrayList(); public ArrayList Tabs {
4
by: Arjen | last post by:
Hi, I have a class with some attributes. For example class person with name as attribute. I have add multiple persons in an arraylist. Now I need a function to get/find a person by the name...
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...
9
by: Rodusa | last post by:
How can I update the rank object inside the arraylist based on its index? ContainerKeywords k = new ContainerKeywords(); int rank = 0; if (ArItems.Contains(sItem)==false) // if did not find...
9
by: Dennis | last post by:
When a class (myownclass) inheirits another class, how can I get an object reference to the underlyng MyBase class instance from within myownclass. The base class has a method that I want to...
3
by: Sam | last post by:
Hi Everyone, I have a stucture below stored in an arraylist and I want to check user's input (point x,y) to make sure there is no duplicate point x,y entered (string label can be duplicated). Is...
6
by: AAJ | last post by:
Hi all I have some objects that I add to an ArrayList. Each object is from the same class and has methods etc. Each can be identified by a unique property, in this case PK e.g. PK =1 for...
0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
6
by: Doug | last post by:
Hi, I want to create a collection of objects that will be used as a property of another object. So for example if I had a Customer object, I would like to have an AddressCollection property...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.