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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:45:49+00:00 2026-05-23T16:45:49+00:00

The orderedDictionary instantiation is this: IOrderedDictionary orderedDictionary= gridview.DataKeys[index].Values; orderedDictionary is read only. How can

  • 0

The orderedDictionary instantiation is this:

IOrderedDictionary orderedDictionary= gridview.DataKeys[index].Values;

orderedDictionary is read only.

How can I make a deep copy of orderedDictionary that is not read only? Serialization/deserialization doesn’t work cause it also copies the read only part.

  • 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-23T16:45:49+00:00Added an answer on May 23, 2026 at 4:45 pm

    The easiest way would be to just copy the objects:

    var newDictionary = new OrderedDictionary();
    foreach(DictionaryEntry de in orderedDictionary)
    {
        newDictionary.Add(de.Key, de.Value);
    }
    

    UPDATE:
    This code will NOT create a deep copy of the values in the dictionary.
    Example:

    var orderedDictionary = new OrderedDictionary();
    orderedDictionary.Add("1", new List<int> { 1, 2 });
    
    var newDictionary = new OrderedDictionary();
    foreach(DictionaryEntry de in orderedDictionary)
    {
        newDictionary.Add(de.Key, de.Value);
    }
    

    Both dictionary will contain one entry with the key “1” and the same list. Removing an item from this list in any of the dictionaries will also change the contents of the list in the other dictionary, because there only IS one list.

    Console.WriteLine(((List<int>)orderedDictionary["1"]).Count);
    Console.WriteLine(((List<int>)newDictionary["1"]).Count);
    Console.WriteLine(ReferenceEquals(orderedDictionary["1"], newDictionary["1"]));
    ((List<int>)orderedDictionary["1"]).Remove(1);
    Console.WriteLine(((List<int>)orderedDictionary["1"]).Count);
    Console.WriteLine(((List<int>)newDictionary["1"]).Count);
    

    This will output the following:

    2
    2
    True
    1
    1
    

    Assigning a new value to a key in one of the dictionary however has no effect on the other dictionary:

    newDictionary["1"] = new List<int>{3,4};
    Console.WriteLine(ReferenceEquals(orderedDictionary["1"], newDictionary["1"]));
    Console.WriteLine(((List<int>)orderedDictionary["1"]).Count);
    Console.WriteLine(((List<int>)newDictionary["1"]).Count);
    

    This will output:

    False
    2
    3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some questione about NSMutableDictionary. I read that they are only a wrapper
No one said that OrderedDictionary is having two copies of elements, one in a
I need a collection data-structure that can do the following: Be sorted Allow me
In my OrderedDictionary I want to replace an object. I saw that the OrderedDictionary
I'd actually like to start by admitting that I'm terrified to ask this question.
How do I get the key and value of item from OrderedDictionary by index?
There doesn't appear to be a generic implementation of OrderedDictionary (which is in the
I am considering of using the OrderedDictionary. As a key I want to use
Is there an collection in .net that allows the storing KeyValuePair<string, string> that keeps
I am loading a big treeview in a seperate thread. This thread starts at

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.