473,394 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Copying a jagged array

8
I've made this short test code, to illustrate my problem:

Expand|Select|Wrap|Line Numbers
  1. int[][] j = new int[2][];
  2. j[0] = new int[] { 0 };
  3.  
  4. int[][] k = (int[][])j.Clone();
  5.  
  6. k[0][0] = 1;
  7.  
  8. Console.WriteLine("j: "+j[0][0].ToString());
  9. Console.WriteLine("k: " + k[0][0].ToString());
  10.  
The program writes out both j and k as 1, where it should write j as 0.

I've tried with both Clone, CopyTo and Array.Copy, all with the same result.

Anyone who can tell me what im doing wrong?
Nov 27 '07 #1
3 1532
CyberSoftHari
487 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1.             int[][] j = new int[2][];
  2.             j[0] = new int[] { 0 };
  3.  
  4.             int[,] k = new int[1,1]; // = (int[][])j.Clone();
  5.  
  6.             k[0,0] = 1;
  7.  
  8.             Console.WriteLine("j: " + j[0][0].ToString());
  9.             Console.WriteLine("k: " + k[0,0].ToString());
Try this.
Nov 27 '07 #2
Dr1ZZ
8
You're creating an entirely new array (multidimensional instead of jagged), why?

I'm sorry I didnt explain it in my post, but i thought the code illustrated it well enough.
What I want is a copy of my original jagged array, but instead it references to the original, even when I'm using Clone/CopyTo/Array.Copy
Nov 27 '07 #3
CyberSoftHari
487 Expert 256MB
Ehm ok, why if I may ask? :/
Sorry I said the thread which I post.
Nov 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ron | last post by:
Hi, I am Serializing a Jagged Array and it works fine. The qusetion i have is way dose the XML formatting do the following. I have a single-dimensional array that has 21 elements of type int,...
2
by: Jannis Linxweiler | last post by:
Hi NG! I have a problem with my unsafe code. I'd like to get a pointer on a jagged array like this: double arr = new double; for (int i....); arr = new double;
6
by: Carlos | last post by:
Ok I have the following Jagged array double mData = new double; for (int x = 0; x <= 259200-1; x++) { mData=new double; } And I load the data in to the array :
2
by: deko | last post by:
I trying to create a jagged array of two arrays, with the second array being an array of two-dimensional arrays. A graphical representation might look like this: x y y y x y x y y x ...
0
by: craig.conboy | last post by:
Using MC++ .Net 2.0, with the CLR Profiler (from Microsoft) I am seeing that 3 blocks of memory, each ~48MB in size, being allocated by some code that initializes a managed array. It is a jagged...
2
by: tiberiu.motoc | last post by:
Hi. I've asked this question on the MSDN forums, but I've had no replies. I'm really stuck, so I'm gonna try my luck here. I have a Java web service which contains a simple function; the...
5
by: TS | last post by:
is there some code somewhere that does this? i have a jagged array that is not jagged, it has an equal number of rows and columns in each array so it should convert but want to get the code to do...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
3
by: pinkfloydfan | last post by:
Hi there I have a C# program that produces a lot of data that I currently store in a jagged array and I have a couple of questions that I was hoping someone might shed some light on for me...
7
by: ASIM ABBAS | last post by:
Sir plz explain and also send me the code of dynamic jagged array i make static jagged array but how we make dynamic jagged array
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.