Delete Element from array

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I created such procedure for deleting element from my dynamic array
because I could not find such possibility from .Net .


Private aintABC() As Int32

'' Initialization somewhere in another procedure

Private Sub DeleteFromArray(ByVal intIndex As Integer)
Dim i As Integer
For i = intIndex + 1 To aintABC.Length - 1
aintABC(i - 1) = aintABC(i)
Next
ReDim Preserve aintABC(aintABC.Length - 2)
End Sub


Maybe somebody know how I can do it without iteration or .Net does not
have any standart decision.

Thanks
 
* (e-mail address removed) (Mike) scripsit:
I created such procedure for deleting element from my dynamic array
because I could not find such possibility from .Net .

Use an 'ArrayList' instead.
 
You don't know the use of the table ... So you can't give this advice !!!
 
Mike,
As the others have suggested.

If boxing of value types is a concern, for an array of Integer (and other
value types) I would consider using Array.Copy to copy the elements before &
after the element that I was deleting.

Something like:
Private Shared Sub DeleteFromArray(ByRef aintABC() As Integer, ByVal
intIndex As Integer)
Dim result(aintABC.Length - 2) As Integer
Array.Copy(aintABC, 0, result, 0, intIndex)
Array.Copy(aintABC, intIndex + 1, result, intIndex,
aintABC.Length - intIndex - 1)
aintABC = result
End Sub

For an array of reference types or if boxing is not an issue. I would use an
ArrayList or a class derived from CollectionBase. More then likely I would
use an ArrayList, until performance was proven to be an issue via profiling.


When Whidbey (VS.NET 2005) ships we will have a generic ArrayList like class
where we will be able to delete from the middle of a collection of Integers,
without the expense of boxing the elements...

Hope this helps
Jay
 
I would gently remarks that : This is not ever possible to use an ArrayList
at the place of a Table. It depends the use of.

Bismark
 
* "Bismark Prods said:
I would gently remarks that : This is not ever possible to use an ArrayList
at the place of a Table. It depends the use of.

I agree, but if the OP is talking about a dynamic array, an arraylist is
more likely the better solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top