Clearing an array of images
-
Hi. I have an array of images like:
Image[] images = new Image[3];
After populating it with three images, i want to remove all of them and prepare it for the next set of three images by clearing the array. i have tried:
images.Clear();
as in an array but this does not work. How do i remove the images? Thank you in advance.
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
Hi. I have an array of images like:
Image[] images = new Image[3];
After populating it with three images, i want to remove all of them and prepare it for the next set of three images by clearing the array. i have tried:
images.Clear();
as in an array but this does not work. How do i remove the images? Thank you in advance.
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
Have you tried repeating step 1
images = new Image[3];
Never underestimate the power of human stupidity RAH
-
Hi. I have an array of images like:
Image[] images = new Image[3];
After populating it with three images, i want to remove all of them and prepare it for the next set of three images by clearing the array. i have tried:
images.Clear();
as in an array but this does not work. How do i remove the images? Thank you in advance.
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
Wamuti wrote:
How do i remove the images?
What do you mean by "remove"? you can't remove anything from an array, each element will be there, all you can do is replace it, possibly by null. If you want a variable number of elements, use a real collection such as a
List<Image>
If you are worried about memory clean-up (and you should), then call Dispose() on each non-null element before replacing it by something else (unless the same image is still needed elsewhere). :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
Hi. I have an array of images like:
Image[] images = new Image[3];
After populating it with three images, i want to remove all of them and prepare it for the next set of three images by clearing the array. i have tried:
images.Clear();
as in an array but this does not work. How do i remove the images? Thank you in advance.
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
If you want the elements to vary and you want to keep using an array and you don't want to reference a new array, you could always try:
Image[] images = new Image[3];
// Populate 3 images...
Array.Resize<Image>(ref images, 0);
Array.Resize<Image>(ref images, 4);
// Populate 4 images...