Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Get the last item in ArrayList

Reply
 
Old 10-24-2008   #1 (permalink)
Curious


 
 

Get the last item in ArrayList

I have an ArrayList outputList. I only need to get the last item:

int last = outputList.LastIndexOf(null);
ExtremeBucket lastItem =
(ExtremeBucket)outputList[last];

Please confirm if this is the right way. Thanks!

My System SpecsSystem Spec
Old 10-24-2008   #2 (permalink)
Family Tree Mike


 
 

Re: Get the last item in ArrayList

No, to get the last item in the list, use

int last = outputList [outputList.Count () - 1];

I have no idea how you are converting an int to an ExtremeBucket though.

"Curious" <fir5tsight@xxxxxx> wrote in message
news:2cccbb3d-cbdd-49e6-8b76-992404df2fa0@xxxxxx
Quote:

>I have an ArrayList outputList. I only need to get the last item:
>
> int last = outputList.LastIndexOf(null);
> ExtremeBucket lastItem =
> (ExtremeBucket)outputList[last];
>
> Please confirm if this is the right way. Thanks!
My System SpecsSystem Spec
Old 10-24-2008   #3 (permalink)
Curious


 
 

Re: Get the last item in ArrayList

Family Tree Mike:

Thanks! FYI, I used the following approach you've suggested:

ExtremeBucket lastItem =
(ExtremeBucket)outputList[outputList.Count - 1];

Each item is type of ExtremeBucket.
My System SpecsSystem Spec
Old 10-24-2008   #4 (permalink)
Jack Jackson


 
 

Re: Get the last item in ArrayList

On Fri, 24 Oct 2008 14:39:50 -0700 (PDT), Curious
<fir5tsight@xxxxxx> wrote:
Quote:

>Family Tree Mike:
>
>Thanks! FYI, I used the following approach you've suggested:
>
> ExtremeBucket lastItem =
>(ExtremeBucket)outputList[outputList.Count - 1];
>
>Each item is type of ExtremeBucket.
You should consider using the generic List instead of ArrayList. That
way your access to the list will be type safe.
My System SpecsSystem Spec
Old 10-24-2008   #5 (permalink)
Family Tree Mike


 
 

Re: Get the last item in ArrayList

I agree with Jack, that List<ExtremeBucket> will be better for you in the
long run.

"Curious" <fir5tsight@xxxxxx> wrote in message
news:691b4373-6e3e-445a-a9e0-8083992fcd40@xxxxxx
Quote:

> Family Tree Mike:
>
> Thanks! FYI, I used the following approach you've suggested:
>
> ExtremeBucket lastItem =
> (ExtremeBucket)outputList[outputList.Count - 1];
>
> Each item is type of ExtremeBucket.
My System SpecsSystem Spec
Old 10-27-2008   #6 (permalink)
Curious


 
 

Re: Get the last item in ArrayList

Quote:

> I agree with Jack, that List<ExtremeBucket> will be better for you in the
> long run.
I do intend to use List<ExtremeBucket>. However, since this must be
coded in Visual Studio 2003 (which is compatible with .NET 1.1), I
have to use ArrayList because it doesn't recognize generic.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
rename-item, move-item and special chars. PowerShell
Empty Arraylist is null? PowerShell
Copy-Item : Container cannot be copied onto existing leaf item. PowerShell
Marshalling ArrayList .NET General
Thread-safety: Change property of items in arraylist versus removingitems from the arraylist .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46