468,463 Members | 2,046 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

Delete Element from array

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
Nov 20 '05 #1
7 9677
* y1***@yahoo.com (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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
You could do it with CopyTo method.

Bismark
"Mike" <y1***@yahoo.com> a écrit dans le message de
news:93**************************@posting.google.c om...
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

Nov 20 '05 #3
You don't know the use of the table ... So you can't give this advice !!!
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> a écrit dans le
message de news:c6************@ID-208219.news.uni-berlin.de...
* y1***@yahoo.com (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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4
* "Bismark Prods" <tr*******@vtxnet.ch> scripsit:
You don't know the use of the table ... So you can't give this advice !!!


?!?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
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
"Mike" <y1***@yahoo.com> wrote in message
news:93**************************@posting.google.c om...
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

Nov 20 '05 #6
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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> a écrit dans le
message de news:c6************@ID-208219.news.uni-berlin.de...
* "Bismark Prods" <tr*******@vtxnet.ch> scripsit:
You don't know the use of the table ... So you can't give this advice
!!!
?!?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #7
* "Bismark Prods" <tr*******@vtxnet.ch> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Westcoast Sheri | last post: by
4 posts views Thread by Shea Martin | last post: by
3 posts views Thread by Brian Underhill via DotNetMonster.com | last post: by
7 posts views Thread by JH Programmer | last post: by
29 posts views Thread by Jon Slaughter | last post: by
29 posts views Thread by =?Utf-8?B?R2Vvcmdl?= | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.