请解释这个对象[,] obj Data = new Object [rowCnt,20] [英] Please explain this object[,] obj Data = new Object[rowCnt, 20]
问题描述
我在我的项目中得到了这个: - object [,] objData = new Object [rowCnt,20] ...
请让我知道为什么逗号( ,)在Object之后的方括号中。
以及上面代码行中指定的rowCnt和20......
OK:它指定这是一个二维数组。
对象 [] ar = new 对象 [ 5 ];创建一个包含5个对象的数组 - 这是一维数组,因为要访问它,您只需提供一个坐标,或
index
:
object o1 = ar [ 0 跨度>];
object o2 = ar [ 1 ];
object o3 = ar [ 2 ];
object o4 = ar [ 3 ];
object o5 = ar [ 4 ];添加时一个逗号,你创建一个二维数组:
object [,] ar = new object [ 3 , 5 ];这将创建一个包含15个对象的数组 - 三行乘五列 - 它需要两个坐标或
索引
访问:
object o1 = ar [ 0 , 0 ];
object o2 = ar [ 0 , 1 跨度>];
object o3 = ar [ 0 , 2 跨度>];
object o4 = ar [ 0 , 3 跨度>];
object o5 = ar [ 0 , 4 跨度>];
object o6 = ar [ 1 , 0 跨度>];
object o7 = ar [ 1 , 1 跨度>];
object o8 = ar [ 1 , 2 跨度>];
object o9 = ar [ 1 , 3 跨度>];
object o10 = ar [ 1 , 4 跨度>];
object o11 = ar [ 2 , 0 跨度>];
object o12 = ar [ 2 , 1 跨度>];
object o13 = ar [ 2 , 2 跨度>];
object o14 = ar [ 2 , 3 跨度>];
object o15 = ar [ 2 , 4 ];还有一个Jagged数组,其中每行的列数不相同:
< span class =code-keyword> object [] [] ar = new object [ 3 ];
ar [ 0 ] = new object [ 5 ];
ar [ 1 ] = new object [ 2 ];
ar [ 2 ] = new object [ 1024 ];同样,这需要索引,但这次你需要更加小心!
object 01 = ar [ 0 ] [ 3 ];没问题,但
< pre lang =c#> object o1 = ar [ 1 ] [ 3 ];会给你一个错误,因为第二行没有足够的元素!
I got this in my project:- object[,] objData = new Object[rowCnt, 20] ...
Please let me know why comma(,) is there in square brackets after Object.
and what "rowCnt" and "20" specify in the above line of code...
OK: it specifies that this is a two dimensional array.
object[] ar = new object[5];creates an array of 5 objects - this is a one dimensional array because to access it you only need to provide one coordinate, or
index
:
object o1 = ar[0]; object o2 = ar[1]; object o3 = ar[2]; object o4 = ar[3]; object o5 = ar[4];When you add a comma, you create a two dimensional array:
object[,] ar = new object[3, 5];This creates an array of 15 objects - three rows by five columns - and it requires two coordinates or
indexes
to access:
object o1 = ar[0, 0]; object o2 = ar[0, 1]; object o3 = ar[0, 2]; object o4 = ar[0, 3]; object o5 = ar[0, 4]; object o6 = ar[1, 0]; object o7 = ar[1, 1]; object o8 = ar[1, 2]; object o9 = ar[1, 3]; object o10 = ar[1, 4]; object o11 = ar[2, 0]; object o12 = ar[2, 1]; object o13 = ar[2, 2]; object o14 = ar[2, 3]; object o15 = ar[2, 4];There is also a Jagged array, where the number of columns for each row are not the same:
object[][] ar = new object[3]; ar[0] = new object[5]; ar[1] = new object[2]; ar[2] = new object[1024];Again, this requires to indexes, but this time you have to be a lot more carefull!
object 01 = ar[0][3];is fine, but
object o1 = ar[1][3];will give you an error because the second row does not contain enough elements!
这篇关于请解释这个对象[,] obj Data = new Object [rowCnt,20]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!