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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:50:44+00:00 2026-05-13T21:50:44+00:00

My idea was to copy a dictionary while resetting all the values of the

  • 0

My idea was to copy a dictionary while resetting all the values of the previous one, so i have this instruction:

var dic2 = new Dictionary<string, int>(dic.ToDictionary(kvp => kvp.Key, kvp => 0));

However i had an unexpected problem doing this, since the new copied dictionary doesnt have the same order of keys of the previous one.

Any way to reset the values but to maintain the same order of keys? Witouth resorting to some type of sorting?

  • 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-13T21:50:44+00:00Added an answer on May 13, 2026 at 9:50 pm

    The answer is not to rely on the order of keys in a Dictionary<,> in the first place. It’s emphatically not guaranteed.

    This is documented on MSDN, but not nearly as clearly as I’d have wanted:

    For purposes of enumeration, each item
    in the dictionary is treated as a
    KeyValuePair structure
    representing a value and its key. The
    order in which the items are returned
    is undefined.

    .NET doesn’t currently have an insertion-order-preserving dictionary implementation as far as I’m aware 🙁

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

Sidebar

Related Questions

If I have a: Dictionary<string, int> How do I copy all the values into
I'm wondering why I can't just cast (I have a vague idea this might
I am having problem with the logic. I have no idea how to copy
This is perhaps a half-baked idea, but can I copy the environment of an
Simple idea: I have two images that I want to merge, one is 500x500
I have no idea how to do this. What I am trying to do
I have no idea. This causes seemingly random time-outs. These in turn break the
idea Via jQuery, I was able to mark all :first-child and :last-child elements in
Idea: I want to make smth like real time electronic blackboard. Many users have
I have a table that looks like this: <table name=exercises id=workout-table> <tr> <th>Name</th> <th>Reps/Intervals</th>

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.