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

  • SEARCH
  • Home
  • 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 8057781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:08:45+00:00 2026-06-05T09:08:45+00:00

I am declaring a list like below and then I am adding 12 items

  • 0

I am declaring a list like below and then I am adding 12 items to it:

List lstPolygonWkt = new List();

foreach (var i in items)
lstPolygonWkt.Add(i.PolygonWkt);

One should think that the list now contains 12 elements, right?
But to my surprise it turns out that the list suddenly contains 16 items and then the last 4 items are null.
I don’t understand why my list which should be 12 items is suddenly 16 items. Any idea why? And how to make the list only 12 items as it should be?

I will paste a couple of screen shots:

enter image description here

enter image description here

  • 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-05T09:08:46+00:00Added an answer on June 5, 2026 at 9:08 am

    The list reserves memory in chunks everytime it needs to grow in capacity. Hence capacity reports 16, but count only reports 12. Null items contribute towards the count.

    The list class provides the TrimExcess method to remove unutilised space.

    Also, specifying the capacity upfront in the constructor results in only one memory grab ( assuming you don’t exceed that capacity).

    Your screenshot shows a count of 12 with a capacity of 16. If memory serves, the list attempts to double its size (or at the very least definitely defaults to 4, then goes to 8, then 16). As you have 12 items, you triggered the jump from 8 to 16 capacity.

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

Sidebar

Related Questions

I'm receiving an exception like cannot convert from 'List' to 'string' when i'm declaring
How can add/remove/replace LIST in cookies using C#. //Declaring the List for image list
Rather than declaring a list at the start of the method, adding to it
is there's any difference between declaring an arrayList polymorphically like that: List<Integer> iL =
i am declaring cg-point or rect as const it giving above error any one
I'm building a driver's application for employment and I'd like the list of 'accidents'
I am declaring a List object property with: @XmlRootElement(namespace = ...) @XmlType public class
One common dilemma I have faced throughout programming is regarding declaring variables inside a
I have a list of collapsible times like 9:00 - 10:00 and near that
Currently, error messages on my Zend Form render like this below the elements: <ul

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.