473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 9926
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Westcoast Sheri | last post by:
Any way to do a simple delete from array? In other words, what would be the *easiest* (and fastest php runtime) way to delete "banana" from the following array: $my_array = array( "apple",...
4
by: Shea Martin | last post by:
Which of the following do I use delete instead of just delete. //1.) // not sure about this one, as char is of size 1 char *str = new char; //2.) //not sure about this one, as it is a...
3
by: Brian Underhill via DotNetMonster.com | last post by:
I am trying to delete an element from an array. I have an array of 52 elements and I want to search for an element and delete it. Therefore, making it an array of 51 elements. is it just ...
6
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
7
by: JH Programmer | last post by:
Hi, is there any ways that allow us to delete an element in between? say int_val: 1 int_val: 2 int_val: 3
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
7
by: =?utf-8?B?5YiY5piK?= | last post by:
Hi, folks, Is it possible to delete an element from a sorted array with O(1) time? Best regards
29
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I remembered delete is implemented through operator overloading, but I am not quite clear. Could anyone recommend some links about how delete is implemented so that I can...
3
by: vaibhavkanwal | last post by:
Hi, i am trying to initialize a dynamic array and use this array to conduct linear search. I know about new and delete but as a pointer can be incremented by the sizeof its dataype, i wanted to...
12
by: subramanian100in | last post by:
Suppose class Base { public: virtual ~Test() { ... } // ... }; class Derived : public Base
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.