working with 2D Array
-
int[] W=new int[10]; int[][] wind=new int[2][]; Color c1 = h.GetPixel(1,1); W[0]=c1.ToArgb(); wind[0][0]=W[0]; this code give me run time error at wind[0][0]=W[0]; I do not know why,is there any error,can some one guide me,
-
int[] W=new int[10]; int[][] wind=new int[2][]; Color c1 = h.GetPixel(1,1); W[0]=c1.ToArgb(); wind[0][0]=W[0]; this code give me run time error at wind[0][0]=W[0]; I do not know why,is there any error,can some one guide me,
You forgot to allocate the size of the second dimension of variable wind. You need to do something like this:
int[][] wind = new int[2][]; wind[0] = new int[3]; wind[1] = new int[5];
Set the size of the first dimension to 2 (you've done that). Then you need to set the sizes of the second dimension for each of the elements (!) in the first dimension. By the way, if you want the sizes of the second dimension to be the same, you might consider using a two-dimensional array like this:int[,] wind = new int[2, 3];
-
You forgot to allocate the size of the second dimension of variable wind. You need to do something like this:
int[][] wind = new int[2][]; wind[0] = new int[3]; wind[1] = new int[5];
Set the size of the first dimension to 2 (you've done that). Then you need to set the sizes of the second dimension for each of the elements (!) in the first dimension. By the way, if you want the sizes of the second dimension to be the same, you might consider using a two-dimensional array like this:int[,] wind = new int[2, 3];
Hello,
jjansen wrote:
By the way, if you want the sizes of the second dimension to be the same, you might consider using a two-dimensional array like this: int[,] wind = new int[2, 3];
Thank you for the information about the 2D-array. (never used it before) How do I get access to a spezial array? (int[] intarray = wind[0]) //doesn't work Thanks for your time Martin