How to change this to 1D array?
-
16 aprilie 2012 08:26
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;
Toate mesajele
-
16 aprilie 2012 08:55
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
- Editat de Centigradz 16 aprilie 2012 08:56
- Marcat ca răspuns de Bob ShenMicrosoft Contingent Staff, Moderator 1 mai 2012 03:35
-
16 aprilie 2012 09:10
If you want to represent a as array, then try this:
int [] a1D = a.SelectMany( row => row ).ToArray();- Marcat ca răspuns de Bob ShenMicrosoft Contingent Staff, Moderator 1 mai 2012 03:35
-
16 aprilie 2012 12:34
The same question has been answered here: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/1be9c382-f0fa-46fa-b1c9-9d12374d1c15- Propus ca răspuns de servy42Microsoft Community Contributor 16 aprilie 2012 14:12
- Marcat ca răspuns de Bob ShenMicrosoft Contingent Staff, Moderator 1 mai 2012 03:35
-
16 aprilie 2012 17:04
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
- Marcat ca răspuns de Bob ShenMicrosoft Contingent Staff, Moderator 1 mai 2012 03:35