How to change this to 1D array?
-
Monday, April 16, 2012 8:26 AM
any kind soul can help me to convert this to 1D array please?? I'm new to programming and I have no idea on how to change this to 1D...
int[][] a = new int[][] {new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
int[][] b = new int[][]{ new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
int x = 0;
int y = 0;
All Replies
-
Monday, April 16, 2012 8:55 AM
Hi,
i can't understand wht you mean with "conver to 1d array". First i'll try to explain you what this code means.
int[] <- this is an array of ints
int[,] <- multi-dimentional array
int[][] <- this is an array of ints containing another array of ints, so if you trying to access this you can access this in the following way
int[][] i = new int[][]{};
int[] j = i[0]; //this returns an array inside i array.
hope i explained well with my poor english.
Bilhan silva
- Edited by Centigradz Monday, April 16, 2012 8:56 AM
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Tuesday, May 01, 2012 3:35 AM
-
Monday, April 16, 2012 9:10 AM
If you want to represent a as array, then try this:
int [] a1D = a.SelectMany( row => row ).ToArray();- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Tuesday, May 01, 2012 3:35 AM
-
Monday, April 16, 2012 12:34 PM
The same question has been answered here: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/1be9c382-f0fa-46fa-b1c9-9d12374d1c15- Proposed As Answer by servy42Microsoft Community Contributor Monday, April 16, 2012 2:12 PM
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Tuesday, May 01, 2012 3:35 AM
-
Monday, April 16, 2012 5:04 PM
You can loop through length of array and declare it to multiple single dimensional array.
Learn more from this link http://msdn.microsoft.com/en-us/library/2yd9wwz4%28v=vs.71%29.aspx
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Tuesday, May 01, 2012 3:35 AM

