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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:00:16+00:00 2026-05-25T18:00:16+00:00

I have a dictionary structure, with multiple key value pairs inside. myDict.Add(key1, value1); myDict.Add(key2,

  • 0

I have a dictionary structure, with multiple key value pairs inside.

myDict.Add(key1, value1);
myDict.Add(key2, value2);
myDict.Add(key3, value3);

My dictionary is used as a data source for some control. In the control’s dropdown I see the items are like this:

key1
key2
key3

The order looks identical to my dictionary.
I know Dictionary is not like arrayList – you can get the index or so.
I cannot use sortedDictionary.
Now I need to add one more key value pair to this dictionary at some point of my program and I hope it has the same effect as I do this:

myDict.Add(newKey, newValue);
myDict.Add(key1, value1);
myDict.Add(key2, value2);
myDict.Add(key3, value3);

If I do this, I know newKey will display in my control as first element.

I have an idea to create a tempDict, put each pair in myDict to tempDict, then clear myDict, then add pairs back like this:

myDict.Add(newKey, newValue);
myDict.Add(key1, value1);
myDict.Add(key2, value2);
myDict.Add(key3, value3);

Is there better way than this?

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-25T18:00:17+00:00Added an answer on May 25, 2026 at 6:00 pm

    Dictionary<K,V> does not have an ordering. Any perceived order maintenance is by chance (and an artifact of a particular implementation including, but not limited to, bucket selection order and count).

    These are the approaches (just using the Base Class Libraries BCL) I know about:

    1. Lookup<K,V>
      • .NET4, immutable, can map keys to multiple values (watch for duplicates during building)
    2. OrderedDictionary
      • Old, non-generic, expected Dictionary performance bounds (other two approaches are O(n) for “get(key)/set(key)”)
    3. List<KeyValuePair<K,V>>
      • .NET2/3 okay, mutable, more legwork, can map keys to multiple values (watch for duplicates in inserts)

    Happy coding.


    Creating a hash data-structure that maintains insertion order is actually only a slight modification of a standard hash implementation (Ruby hashes now maintain insertion order); however, this was not done in .NET nor, more importantly, is it part of the Dictionary/IDictionary contract.

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

Sidebar

Related Questions

I have a plist with the following architecture/structure: dictionary key1 item1 key2 item2 key3
Does VBA have dictionary structure? Like key<>value array?
I have a dictionary, with 300 key value pairs, where each of the keys
I have a Dictionary that when I add multiple values to it, the items
I have a Dictionary with some simple string,string value pairs. The problem is that
I have a dictionary that I normally access with a key, so I need
Is there a C# data structure to map keys to multiple values? I have
I have several layers of function calls, passing around a common dictionary of key
I have two dictionaries with the same structure: Dictionary<string, int> foo = new Dictionary<string,
I have trivial question: I couldn't find a dictionary data structure in R, so

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.