Re: Accessing Arraylist Collection

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/02/05


Date: Wed, 2 Mar 2005 21:44:44 -0000

JJ <JJ@discussions.microsoft.com> wrote:
> I have created an Arraylist object from an Arraylist class.
> I added rows to the arraylist object and I need to find a particular record
> in my arraylist. How do I do this?

Do you mean by row number, or by row object? If it's by row object, use
IndexOf. If it's by row number, use the indexer:

object o = arrayList[rowNumber];

> Also if I was in the middle of building the arraylist and wanted to
> call the last record added to arraylist object how can I do this?

Use the indexer again, along with the Count property:

object last = arrayList[arrayList.Count-1];

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too