-
Aug 2nd, 2009, 01:10 PM
#1
Thread Starter
Addicted Member
Arrays: Removing Items
I'm wondering what the proper way to remove an item from an array is. The way i am doing it at the moment is:
Code:
MyArray(0) = Nothing
Is this the best way to do it as i'm having problems with my programme and i think it may be something to do with this?
-
Aug 2nd, 2009, 01:14 PM
#2
Re: Arrays: Removing Items
The proper way is to move everything ABOVE the item down 1 slot, and then resize the array. It's relatively simple, but does take a little coding. In place of using an actual Array, I recommend you use a List(of T) instead.
From my burrow, 2 feet under.
-
Aug 2nd, 2009, 01:38 PM
#3
Thread Starter
Addicted Member
Re: Arrays: Removing Items
That wont work as I need everything else in the array to stay where it is
-
Aug 2nd, 2009, 01:39 PM
#4
Thread Starter
Addicted Member
Re: Arrays: Removing Items
I also can't use the list as i'm using a two dimensional array
-
Aug 2nd, 2009, 01:57 PM
#5
Re: Arrays: Removing Items
What type are you putting into the array then? Why are you using a single dimension in code if it's multi-dimensional?
From my burrow, 2 feet under.
-
Aug 2nd, 2009, 02:41 PM
#6
Thread Starter
Addicted Member
Re: Arrays: Removing Items
The array contains graphics from a class that i have created. I was just using that code as an example what i'm actually doing is:
Code:
Blocks(TestPosition.X, TestPosition.Y) = Nothing
-
Aug 2nd, 2009, 02:54 PM
#7
Re: Arrays: Removing Items
What your "problems with my program".
-
Aug 2nd, 2009, 03:08 PM
#8
Thread Starter
Addicted Member
Re: Arrays: Removing Items
Basically I am setting certain items in the array to nothing and when rendering all blocks in the array to the screen its still displaying the items that have been set to nothing. I have put breakpoints on my code and I checked the array and the items are set to nothing so im not sure why it's still drawing the blocks.
-
Aug 2nd, 2009, 03:20 PM
#9
Re: Arrays: Removing Items
Then maybe it's a problem with your code somewhere else
-
Aug 2nd, 2009, 04:11 PM
#10
Thread Starter
Addicted Member
Re: Arrays: Removing Items
Ye that's what I was thinking but im starting to loose hope i've been through my code lots of times and still can't figure out why. If i'm removing blocks that were originally in the array then it works fine but if im removing a block that was added to the array then it sets it to nothing but still display it on screen.
-
Aug 2nd, 2009, 04:59 PM
#11
Re: Arrays: Removing Items
maybe we could help you if we saw your code?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|