![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jul 2006
Location: using Earth.Africa.Egypt.Cairo;
Posts: 73
Rep Power: 3
![]() |
About arrays
hey guys,
well i was just wndering if i can delete indexes from an array,for an example if i have a string entered by the user then i took every word in the string into an index of this array but if i have a few indexes in this array that remain null can i delete them ?? |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Jul 2006
Location: England
Posts: 43
Rep Power: 0
![]() |
Take a look at System.Collections.Generic namespace. There is List<T> which is far far more useful than just a standard Array. There are also other classes in that namepace that act differently but also might be useful.
You cant just remove an item on an array. You have to copy it into a new array up to the point where you want to remove. In your case you would check for nulls to find out where you would stop. You then skip the null index and the continue copying the rest of the array checking for more nulls. I would post some code but you will learn more if you figure it out. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jul 2006
Location: using Earth.Africa.Egypt.Cairo;
Posts: 73
Rep Power: 3
![]() |
thnx jimmy i will try that.
|
|
|
|
|
|
#4 |
|
Expert Programmer
|
If you delete an index from an array there remains a gap there in the memory unless you write some sort of funtion to copy all data past the point backward one index to fill the gap. Same behaviour as you would expect in C++, and well many languages I am sure.
List<T> is a great solution to this since it provides funtions which will do exactly that for you! Oh of course the othe option too is to use something like a linked list which would be faster because your wouldn't be copying data around your memory so much, you just have to update the links between two of the indexes.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Arrays or Vectors? | can342man | C++ | 2 | Apr 20th, 2006 3:57 PM |
| searching for 2D arrays within 2D arrays | HammerCat | C++ | 9 | Mar 14th, 2006 9:16 AM |
| Getting values of (non-dynamic) arrays... | Mcoy | C++ | 3 | Mar 2nd, 2006 7:25 PM |
| Arrays in PHP | MrMan9879 | PHP | 6 | Jan 12th, 2006 9:18 PM |
| Arrays | Gunman | C++ | 17 | Oct 20th, 2005 6:11 AM |