473,404 Members | 2,174 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,404 software developers and data experts.

Creating an Array from a multidimensional array

Hi,

If Im using Jagged arrays, the following is possible:

int[][] arr = new int[10]

for(int i=0; i<10; i++) {
arr[i] = new int[10];
}

int[] arrB = arr[3];

How can I achieve the same thing (i.e. create a single dimensional array
by assigning a copy of some row of a multidimensional array to it) using
multidimensional arrays? Also, in the last line above, a row is not
being assigned or copied by value right? A copy of the reference to the
4th row is being assigned to arrB? Thanks!

Oh and I dont want to use a For loop.. I mean, I don't want to do the
following:

int[] arrB = new int[arr.GetLength(0)];

for(int i=0; i<10; i++) {
arrB[i] = arr[4, i];
}

Thanks

-Phil

Nov 15 '05 #1
1 4143
Use System.Array.Copy

For example:

Array.Copy(arr, arr.GetLength(1)*4, arrB, 0, arr.GetLength(1));
-Andre

@ wrote:
Hi,

If Im using Jagged arrays, the following is possible:

int[][] arr = new int[10]

for(int i=0; i<10; i++) {
arr[i] = new int[10];
}

int[] arrB = arr[3];

How can I achieve the same thing (i.e. create a single dimensional array
by assigning a copy of some row of a multidimensional array to it) using
multidimensional arrays? Also, in the last line above, a row is not
being assigned or copied by value right? A copy of the reference to the
4th row is being assigned to arrB? Thanks!

Oh and I dont want to use a For loop.. I mean, I don't want to do the
following:

int[] arrB = new int[arr.GetLength(0)];

for(int i=0; i<10; i++) {
arrB[i] = arr[4, i];
}

Thanks

-Phil


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: M.Siler | last post by:
<HTML> <HEAD> <TITLE></TITLE> <SCRIPT> <!-- var factor_val = new Array(8,7) factor_val = 68.8 factor_val = 55
9
by: Luke Wu | last post by:
Hello, I'm having some problems understanding 2 dimensional arrays. My problem relates to the following code: #include <stdio.h> #define M 3 #define N 3
4
by: andy.mcvicker | last post by:
Hi Gang I have a large VB program that at one point does a lookup to a small table (26 rows by 3 columns). With this table I have to do some counting and retrieval of data. I'm finding that...
38
by: djhulme | last post by:
Hi, I'm using GCC. Please could you tell me, what is the maximum number of array elements that I can create in C, i.e. char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ; I've...
24
by: Kavya | last post by:
int main (){ int a={{1,2,3},{4,5,6}}; int (*ptr)=a; /* This should be fine and give 3 as output*/ printf("%d\n",(*ptr)); ++ptr;
13
by: Karl Groves | last post by:
I'm missing something very obvious, but it is getting late and I've stared at it too long. TIA for responses I am writing a basic function (listed at the bottom of this post) that returns...
2
by: mareharbor | last post by:
Can anyone help me to change this array to a multidimensional array with 1 more components i want to add another "column" to the array with a similiar specification of "cell.Offset(0, -2).Value". So,...
2
by: nitinm | last post by:
hi I want to make a program whose requirement are as following: 1) it has to create an NxN matrix after reading input (i.e. N) from a file in the main() itself. 2) it has to send the array as...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.