Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Delete item from array?

Back to Forum: Tech Off
  • User profile image

    What is the best way to delete an item from array?

  • User profile image

    Array of what?  Objects?  Set that item to null.  Ints?  Come up with a sentinel (maybe 0, maybe -1) and set that item to the sentinel.

    Are you deleting from the end? ReDim to "one shorter."  From the beginning?  Copy each element down one and ReDim.  From the middle?  Copy each element above down one and ReDim.

    All that assumes order is important.

    If order is not important, you can save a lot of pointer swapping by copying the last element down over the to-be-deleted entry and ReDim'ing.

    What to do if the element is the only one left in the array is left as an exercise. Smiley

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.