Re: reverse a collection

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 11/26/04


Date: Fri, 26 Nov 2004 08:34:59 -0600

Nafri,
It depends on what kind of collection you have, ArrayList has a ToArray
method, if your collection is based on ArrayList either directly or
indirectly (CollectionBase) you can leverage this method.

ArrayList has AddRange & a constructor that accepts a collection, you could
indirectly (CollectionBase) leverage this methods to return the array back
to the collection.

If your collection is not based directly or indirectly on ArrayList, or have
similar methods, then you are correct, looping may be your only option.

Some collections, such as Hashtable, do not support he concept of an order,
so reversing them do not make sense per se.
Hope this helps
Jay

"nafri" <spamMe@spam.net> wrote in message
news:F3D5DA8B-4CAB-425C-A9AD-E747E35531FB@microsoft.com...
>i have a colleciton that i need to reverse. Array has a reverse method. Is
> their any direct way to transfer the items in the collection to an array
> or
> arraylist, reverse the array and transfer back them to the collection.
> Or looping through each element is the only option.
>
> TIA
> nafri



Relevant Pages

  • Re: Arrays to replace very slow loops ?
    ... accomplished by looping through ranges rather than looping through ... That is, with either the range or the array, n is the row ... >>>difference between looping through arrays and looping through ranges) is ... >> no built in method for deleting a "row" in an array without ...
    (microsoft.public.excel.programming)
  • Re: Reversing Array Elements?
    ... Depends what you mean by "actually reverse the array". ... rather than a specification of the language. ... could make such a reordered copy in physical memory as an optimization. ...
    (comp.lang.fortran)
  • Re: Working with floating point numbers.
    ... mechanism but now need to reverse the situation and convert a double to the ... I have reversed the code but come stuck when I try to assign the array to ... I've tried to Asc) the string but it didn't work and when I ... Dim S As MyStrings ...
    (microsoft.public.access.modulesdaovba)
  • Re: Performance Question
    ... Split is more efficient than actually looping through the string. ... second time (parsing it yet again) to assign the data to the array. ...
    (microsoft.public.vb.general.discussion)
  • Re: Cohens paper on byte order
    ... > you changed from a bit sequence to what appears to be ... an array of unsigned char to represent a bit array, ... in the reverse order instead? ... But the user input IS at the beginning a bit array ...
    (sci.crypt)