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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:15:50+00:00 2026-06-01T13:15:50+00:00

Lets tell i’ve got 2D array of dictionaries: public Dictionary<int, string>[,] mat = new

  • 0

Lets tell i’ve got 2D array of dictionaries:

public Dictionary<int, string>[,] mat = new Dictionary<int, string>[3, 5]
{
  { new Dictionary<int, string>(), new Dictionary<int, string>(), new Dictionary<int, string>() },
  { new Dictionary<int, string>(), new Dictionary<int, string>(), new Dictionary<int, string>() },
  { new Dictionary<int, string>(), new Dictionary<int, string>(), new Dictionary<int, string>() },
  { new Dictionary<int, string>(), new Dictionary<int, string>(), new Dictionary<int, string>() },           
  { new Dictionary<int, string>(), new Dictionary<int, string>(), new Dictionary<int, string>() }
}

And i need to copy this to another. I tried all ways.
Something like:

matNew = mat;

But still when i change the first one, ,it automatically change the second one.
I really don’t know how to do this.

  • 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-01T13:15:51+00:00Added an answer on June 1, 2026 at 1:15 pm

    I assume you want a deep copy?

    var matNew = new Dictionary<int, string>[mat.GetLength(0), mat.GetLength(1)];
    for (int i = 0; i < mat.GetLength(0); ++i)
        for (int j = 0; j < mat.GetLength(1); ++j)
            matNew[i, j] = new Dictionary<int, string>(mat[i, j]);
    

    The Dictionary(IDictionary<TKey, TValue>) constructor copies all elements from the specified dictionary, and is probably the fastest way of performing a shallow clone of an existing dictionary. This is suitable for your case, since your keys and values are both immutable (int and string).

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

Sidebar

Related Questions

Lets say we have these 2 sample code : public synchronized void getSomething(){ this.hello
Lets say this is the time-stamp: 2011-07-06T00:00:35.851-07:00 What does that tell me? This is
I'm new here and I'm very stuck. I need help. Hopefully someone can tell
Lets say i wanted to add another variable to the database can anybody tell
Lets say I have this code: <?php class hello { var $greeting = hello;
Lets say I display a window like so: [[TBAddTaskWindowController new] showWindow:self]; Where is the
Lets say I have a vector of int which I've prefilled with 100 elements
I'm currently writing DataTemplate for my custom type lets say FootballPlayer. In this template
Lets assume I have this long insert statement insert into table1 (id, name, phone,
Lets say I've got two tables: album album_id album_name and song album_id song_name track_number

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.