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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:10:39+00:00 2026-05-20T21:10:39+00:00

I have two multi-dimentional arrays declared like this: bool?[,] biggie = new bool?[500, 500];

  • 0

I have two multi-dimentional arrays declared like this:

bool?[,] biggie = new bool?[500, 500];
bool?[,] small = new bool?[100, 100];

I want to copy part of the biggie one into the small. Let’s say I want from the index 100 to 199 horizontally and 100 to 199 vertically.

I have written a simple for statement that goes like this:

for(int x = 0; x < 100; x++)
{
    For(int y = 0; y < 100; y++)
    {
        Small[x,y] = biggie[x+100,y+100];
    }
}

I do this A LOT in my code, and this has proven to be a major performance jammer.

Array.Copy only copies single-dimentional arrays, and with multi-dimentional arrays it just considers as if the whole matrix is a single array, putting each row at the end of the other, which won’t allow me to cut a square in the middle of my array.

Is there a more efficient way to do this?

Ps.: I do consider refactoring my code in order not to do this at all, and doing whatever I want to do with the bigger array. Copying matrixes just can’t be painless, the point is that I have already stumbled upon this before, looked for an answer, and got none.

  • 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-20T21:10:40+00:00Added an answer on May 20, 2026 at 9:10 pm

    In my experience, there are two ways to do this efficiently:

    • Use unsafe code and work directly with pointers.
    • Convert the 2D array to a 1D array and do the necessary arithmetic when you need to access it as a 2D array.

    The first approach is ugly and it uses potentially invalid assumptions since 2D arrays are not guaranteed to be laid out contiguously in memory. The upshot to the first approach is that you don’t have to change your code that is already using 2D arrays. The second approach is as efficient as the first approach, doesn’t make invalid assumptions, but does require updating your code.

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

Sidebar

Related Questions

I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have inherited a middle tier system with some multi-Threading issues. Two different threads,
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two classes, and want to include a static instance of one class
I have two spreadsheets... when one gets modified in a certain way I want
How would you split Regex subexpression matches in to multi-dimensional string arrays? I have
I have a multi dimensional array in PHP. $f = array('one' => array(*doesntmatter*), two
I have some data that goes over three levels, like this: Identifier, Key, Value
I have found this example on StackOverflow: var people = new List<Person> { new
I defined this multi dimensional array in C#: int[,] values = new int[,] {

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.