Get the last item in ArrayList

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

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!
 
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.
 
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.
 
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.
 
I agree with Jack, that List<ExtremeBucket> will be better for you in the
long run.
 
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.
 
Back
Top