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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:11:53+00:00 2026-06-18T08:11:53+00:00

I need to store a list of int – string key-value pairs with a

  • 0

I need to store a list of int–string key-value pairs with a requirement to preserve the order in which items were added. Once it is initialized, it does not change, i.e. nothing added or removed..

At first I thought of using Dictionary<int,string> and everytime I need to access the items use

foreach(var entry in dict.OrderBy(e=>e.Key)) { } //as Key is `int`

However everytime ordering does not seem to be the best option to use.

Now I’ve come to an idea to have a List<Tuple<int, string>>, as soon as List<T> guarantees the order of items.

So, is there a better option?

  • 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-18T08:11:54+00:00Added an answer on June 18, 2026 at 8:11 am

    Looking at the proposed possibilities:

    • Dictionary doesn’t guarantee the order of the items
    • SortedDictionary sorts the items, but not in the order you added them (it sorts based on key comparison),
    • OrderedDictionary keeps the order, but it’s not generic and would introduce unnecessary casting and boxing.

    So I think you should use List<Tuple<int, string>>. It preserves order and it’s good enough for iteration using foreach and indexed access. If you know the size in advance, you could use an array as well, or a read only collection type, as Cuong Le suggested in his answer.

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

Sidebar

Related Questions

is there type is there to store the value <string,string,int> if i use Namedlist(Solr),List
Usually in Java when I need to store 2 int value related to some
I have a file with multiple list of (String,String,Int): [(aaa,aaaaaaaa,13),(asdasdasd,asdea,13)] and I need to
I am a beginner in C++. I need to store list of addresses that
I have a need to store an ordered list of strings and am trying
I'm trying to store a List as a DynamoDB attribute but I need to
I have a list of users in local store that I need to update
I need store just 10 arrays in my app, which I can change from
So I need a linked list to store multiple variables, so I want to
I need to store an array list of strings in a file by encrypting

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.