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 8594521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:13:08+00:00 2026-06-12T00:13:08+00:00

I’m not sure if this is the right question to ask here but please

  • 0

I’m not sure if this is the right question to ask here but please don’t kill me 🙂

I have an argument with a friend about C#’s dictionary…
She tells me that if I have lets say dictionary with 1 element. And the hash code for the key is 100000 then the internal array of the dictionary will be at the size of 100000!

Is it true? I tried to find answers on Google but for some reason I didn’t find for that question.

  • 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-12T00:13:10+00:00Added an answer on June 12, 2026 at 12:13 am

    The default constructor of Dictionary, “has the default initial capacity”, according to MSDN.

    It also states:

    If you can estimate the size of the collection, using a constructor that specifies the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Dictionary.

    One such constructor simply takes an Int32, which initialises the internal storage as follows:

    The initial number of elements that the Dictionary can contain.

    What the “default initial capacity” of the dictionary actually is is an internal implementation detail of the class and as such not exposed in the documentation or public API.

    Disassembling mscorlib with ilspy and examining the default constructor shows that it is implemented as follows:

    public Dictionary() : this(0, null)
    {
    }
    

    That chained constructor is implemented as follows:

    public Dictionary(int capacity, IEqualityComparer<TKey> comparer)
    {
        if (capacity < 0)
        {
            ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
        }
    
        if (capacity > 0)
        {
            this.Initialize(capacity);
        }
    
        this.comparer = (comparer ?? EqualityComparer<TKey>.Default);
    }
    

    i.e. Initialize() is not called at all by the default constructor, either directly or indirectly.

    Initialize() is the method that sets up the internal storage.

    So actually, if you call the default constructor, the internal storage size is not even initialised until you first add an item. So it has essentially a zero size.

    Initialize() is eventually called with a value of zero the first time you call .Add(),
    which sets things up.

    private void Initialize(int capacity)
    {
        int prime = HashHelpers.GetPrime(capacity);
        this.buckets = new int[prime];
        for (int i = 0; i < this.buckets.Length; i++)
        {
            this.buckets[i] = -1;
        }
        this.entries = new Dictionary<TKey, TValue>.Entry[prime];
        this.freeList = -1;
    }
    

    GetPrime(0) returns 3, so this.buckets is set to an array containing three integers.

    The line that assigns a value to this.entries looks a little odd but I don’t see where 100000 comes into this.

    Short answer
    I think your colleague is wrong.

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and

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.