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

  • Home
  • SEARCH
  • 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 6810301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:11:23+00:00 2026-05-26T20:11:23+00:00

Quick sanity check. Is Array.Copy for one dimensional arrays only, or can it handle

  • 0

Quick sanity check. Is Array.Copy for one dimensional arrays only, or can it handle more?

.Net Framework Array.Copy


When reading the specs I read it (probably wrongly) to mean that the match must occur on the second dimension. ie. the source and destination indexes can be different, and we can specify the number of elements.

Okay, so lets hone in on “match”. For an array of rank 2 getting copied to another arry of rank 2, say 10×4 to 20×4, are we saying that we must match on dimensions one and two, or two only. I need it to be on the second dimension only.

Is the only way to achieve this with a looping mechanism in .net. If so, that’s going to be a lot slower than a block copy.


Check this out:

    static void Main(string[] args)
    {

        var A = new int[2,4] {{1, 1, 1, 1}, {2, 2, 2, 2}};

        var B = new int[4,4];
        var C = new int[4, 4];

        Array.Copy(A, 0, B, 4, 8);

        Array.ConstrainedCopy(A, 0, C, 8, 8); // haven't noticed this method before.  Same behaviour though.


    }

Notice that we have to specify the correct starting point in a one dimensional view of the world. I didn’t expect 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-05-26T20:11:24+00:00Added an answer on May 26, 2026 at 8:11 pm

    It supports single and multi-dimensional as long as the source and destination match.

    http://msdn.microsoft.com/en-us/library/k4yx47a1.aspx

    The sourceArray and destinationArray parameters must have the same
    number of dimensions.

    When copying between multidimensional arrays, the array behaves like a
    long one-dimensional array, where the rows (or columns) are
    conceptually laid end to end. For example, if an array has three rows
    (or columns) with four elements each, copying six elements from the
    beginning of the array would copy all four elements of the first row
    (or column) and the first two elements of the second row (or c

    EDIT:

    Think of match in the way it lays out “end to end”. A two dimensional array is really just consecutive memory blocks – a 3 x 4 = 12 blocks. When it copies, it’s going to copy the layout – the end to end layout. The key is the line where they say it’s conceptually laid end to end.

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

Sidebar

Related Questions

I need a quick sanity check. I'm trying to design my views such that
Just a quick sanity check here! If I have a static method in an
Quick one, but thought I'd ask. Is there a better way of getting the
Quick design question. ClassA has a method called DoSomething(args) In DoSomething(), before it can
Quick one for you guys. Say I have a function that outputs a string:
Quick Question Is it possible to have more than 1 config file in a
Quick question that requires a long explanation.. Say I have two tables - one
Quick question - I've finished building an outlook add-in in VS2010, .NET 4.0. I
I am trying to run command line commands from Java and a quick sanity
Quick one: Is there any way to enforce types for variadic functions in PHP?

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.