RE: copying to a multidimensional array?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Daniel Jin (anonymous_at_discussions.microsoft.com)
Date: 04/27/04


Date: Tue, 27 Apr 2004 07:36:03 -0700


     I think you misinterpreted what the documentation says. "When copying <b>between</b> multidimensional array<b>s</b>", that would suggest to me what you need both src and dest to be multidimensional. also, if you look at a list of exceptions the method throws, you would see it clearly states that RankException occurs when src and dest have different ranks.

     I don't know if there's a prebuilt way of doing what you want. but I would just write my own routine to do the copying.
     
     ----- Mark Smith wrote: -----
     
     I'm trying to copy data from a 1D array to a 2D array.
     The obvious thing doesn't work:
     
       int[,] twoDee = new int[2,2];
       int[] oneDee = new int[2] { 1, 2 };
       Array.Copy(oneDee, 2, twoDee, 2, 2);
     
     This causes a RankException. But the MSDN documentation says:
     
       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.
     
     This seems to suggest that there should be some way to accomplish
     this, but I can't find any other syntax that's acceptable. I can
     do it using a jagged 2D array, but I really wanted to avoid creating
     lots of 1D subarray objects. Anybody know the trick?
     



Relevant Pages

  • Re: Is it possible to print enums text?
    ... There is an easy to use trick to accomplish that. ... This causes the array element whose offset is identical to the ... This is wasteful, if not impossible, if the enum values are sparse, ...
    (comp.unix.programmer)
  • Re: best practice if then else
    ... Is the best way to accomplish this a long list of ... the value of the element of the array Arr corresponding to the selected ... buttons select which Easter function is to be tested (years in error, ...
    (comp.lang.javascript)
  • Referencing Variables By Name in a String
    ... so creating them in an array isn't really an option. ... There are several variable groups like this - this is only one of them. ... <now start the code referencing this item> ... Does anyone know a way to accomplish something like this. ...
    (comp.lang.ruby)
  • Re: preg_replace help
    ... Maybe I'm just a G group newbie. ... the buffer are links to user profiles that are composed with the user ... a full search and replace array for every user id especially ... accomplish this using regular exp like this: ...
    (alt.php)
  • Re: Deallocating storage
    ... milkyway wrote: ... I am setting an item in an array to ... to unneeded objects, but you don't necessarily need to explicitly set ... variables or array slots to null to accomplish that. ...
    (comp.lang.java.help)