Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

345
Views
How to set initial capacity to a SortedDictionary?

I'm looking into code optimization of a project of mine and I was wondering how can I set an initial capacity to a SortedDictionary. I know that I can do it to a List and a Dictionary pretty easily in the constructor. But how can I do it to a SortedDictionary?

I thought about doing it like the code below, but I'm not sure if that works and how I could check it, once Dictionary has no capacity property (or has it?).

int capacity = 1000;

SortedDictionary<TKey, TValue> exampleSortedDictionary = new SortedDictionary<TKey, TValue>(new Dictionary<TKey, TValue>(capacity));
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You have no need to specify initial capacity for SortedDictionary<K, V>.

Please note, that Dictionary<K, V> is a hash table that's why the initial capacity (say, 100 "rows") is quite reasonable. Unlike Dictionary<K, V>, SortedDictionary<K, V> is a red-black tree for which capacity has no meaning.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!