Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8074901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:48:53+00:00 2026-06-05T14:48:53+00:00

I have list List <Bitmap> memory = new List<Bitmap>(); . I use this list

  • 0

I have list List <Bitmap> memory = new List<Bitmap>();. I use this list for saving states of image in simple program for working with images. I want to implement operations back and forward, which will iterate between states saved in memory (= saved in list memory).

Memory will have only a limited range, for example 20 states, which means when I will have 20 modifications of an image and I do the 21st, I will delete the first state. Probably by operation memory.RemoveAt(0);. What will happen with the list then? I need the list with -1 items than the previous list and with shifted indexes.

I have list list.Count = 20, I delete the first item, I want list.Count = 19 and shifted indexes – something like trim free spaces so index 1 of original list will have now index 0 and index 2 of original index will have index 1, etc.. I found a method of list TrimExcess, it would do what I want but I’m not sure.

When I will have list of 19 I can save the new state to the last place by Add(), so I will have again the list of 20.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:48:55+00:00Added an answer on June 5, 2026 at 2:48 pm

    Do not confuse a List with an array. An array has fixed positions and a fixed size, while a list does not.

    For arrays, there’s not such thing as “adding” or “removing” items. An array always has the length it was assigned when creating it.

    A list is dynamic in its length. You add items, the list grows. You remove items, the list shrinks. If you add an item to a list, the item is always appended to the list (you can call Insert to insert at a specified position).

    However, at any given time, the entries in a list will have indices starting at 0 ranging to Count-1 (“zero based”). Even if you remove an item at position X “in the middle of the list”, there will be an item at that index (the one that was previously at position X+1).

    Summary: What you described in the “What I need” paragraph is done automatically without any further actions in your code.

    About the TrimExcess method: A list has a Count (the actual number of elements in the list) and a Capacity (the internal number of elements the list can take without having to resize its internal structures). The Capacity can be greater than the Count. This is, because internally the list stores its items in data structures that need to be reorganized when adding/removing.

    To save time when adding, the Capacity grows in larger steps. For example, when you add an item to a list that is full, internally 4 new “places” are created, so that consecutive adds don’t cause too much overhead.

    What TrimExcess does is to reorganize the list’s internal data structures so that the Capacity matches the Count. This takes the more time the more items are in the list, so TrimExcess should only be called when you’re sure that you’ll not need to add/remove any elements anymore.

    In your case: Hands off the TrimExcess method.

    Capacity does not limit the list’s size! In C#, there’s no option to create a list that takes a maximum of X elements. You’ll have to do that yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of bitmap images, How can I add this bitmap to
How to save Geometry as image? For example i have List<Geometry> . I want
I have list of string which I want to add as option in select
I have List I want to sort Desc by Priority, which is int and
i have list of rows that user select and i want to delete them,
i have list of images and on mouse over there is option box shows
I have List with n items. I wish transform my list to new list,
I have created a class call ImageLoader and use memory cache to store all
I currently have a simple list view adapter that holds two rows of text.
I have this code in my WCF Service: public class MyImage { public Image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.