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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:34:11+00:00 2026-05-24T11:34:11+00:00

For a small set of key/value pairs (default 2, max 5), a Dictionary<TKey, TValue>

  • 0

For a small set of key/value pairs (default 2, max 5), a Dictionary<TKey, TValue> seems like overkill. Is there a much simpler data structure that could be used in my case ? I’m caching computed values for certain objects (i.e. <MyClass, double>), so retrieval speed is important.

Thanks

  • 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-05-24T11:34:11+00:00Added an answer on May 24, 2026 at 11:34 am

    A List<KeyValuePair<TKey, TValue>> (created with an appropriate capacity) would probably work just as well in this case… but it wouldn’t be terribly idiomatic. (Just to be clear, you’d simply call Equals on each key element, ignoring the hash code completely.) If List<T> feels a bit heavy to you, you could even go down to KeyValuePair<TKey, TValue>[] if you wanted. Ick, but hey… it’s your code.

    Have you actually tried Dictionary<TKey, TValue> and found it to be too slow? “Seems like overkill” doesn’t seem nearly as good an argument as “I’ve tried it, profiled it, and found an unacceptable amount of my application’s time is spent creating dictionaries and looking up entries in them. I need my application to have performance characteristic X and at the moment I only have Y.”

    If your key type has a particular ordering (and if you were going to perform more lookups on the data structure than you were going to create instances) you could sort the list, meaning you would have a maximum of 3 comparisons for any particular lookup. With only 5 entries you could even hard-code all the potential paths, if you were looking to optimize to the hilt. (You might even have different implementations for 2, 3, 4 and 5 elements. It’s getting a little silly at that point though.) This is basically a SortedList<TKey, TValue> implementation, but you may be able to optimize it a little for your scenario of only having a few entries. Again, it’s worth trying the built-in types first.

    What’s vital is that you know how important this part of your code really is to your overall performance – and when it will be “good enough” so you can stop appropriately.

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

Sidebar

Related Questions

For some small programs in Python, I would like to set, store and retrieve
Given a small set of entities (say, 10 or fewer) to insert, delete, or
I have a small (500kb) swing applet that displays very simple/limited set of small
I display set of images(small). I need to show the larger image(300*300) at some
I am currently playing with Qt trying to set up a small particle system.
I'm trying to set up a simple server side RSA encryption of a small
I have a small ajax application built with php. Using phpMyAdmin I have set
In my c# application i have this small form which is used to set
this is for a small project of mine, I'm trying to set the current
My emacs (on Windows) always launches with a set size, which is rather small,

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.