Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Clearing an array of images

Clearing an array of images

Scheduled Pinned Locked Moved C#
questiondata-structures
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wamuti
    wrote on last edited by
    #1

    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.

    M L A 3 Replies Last reply
    0
    • W Wamuti

      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.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Have you tried repeating step 1

      images = new Image[3];

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • W Wamuti

        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.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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.


        1 Reply Last reply
        0
        • W Wamuti

          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.

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          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...

          [Forum Guidelines]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups