简体   繁体   English

对象C#的多维数组

[英]multidimensional array of object c#

I use an array of array : 我使用array数组:

object[][] of =new object[lenght2][];

Now, what i want is to insert a new array into of[][], I try this : 现在,我想要的是在of [] []中插入一个新数组,我尝试这样:

 for (int i = 0; i < lenght2; i++)
  {
      Act = calcul_resporderbyact(responsable,v); // return array of object
      of[i] = Act;
 }

i want to know how to use some array from this multidimensional-array ?? 我想知道如何从这个多维数组中使用一些数组?

You have couple of mistakes, in your code object[,] of =new object[lenght2][]; 您在object[,] of =new object[lenght2][];代码object[,] of =new object[lenght2][];有几个错误object[,] of =new object[lenght2][];

[,] is not equal to [][] [,]不等于[][]

you can try this: 您可以尝试以下方法:

object[][] of = new object[length2][];
of[i] = Act; //it means you can assign `new[] { new object() };`

Read this: Multidimensional Array [][] vs [,] 阅读: 多维数组[] []与[,]

it says that [,] is multidimensional array and [][] is array of arrays. 它说[,]是多维数组, [][]是数组数组。 So for your use array of arrays is valid. 因此,对于您使用的数组,数组是有效的。

Multidimensional arrays (as opposed to jagged arrays) are always "rectangular", meaning that the length of each entry in the array is also fixed. 多维数组(与锯齿状数组相反)始终为“矩形”,这意味着数组中每个条目的长度也是固定的。

If you want just a list of arrays, which can have different lengths, then use List<object[]> as in 如果只需要一个数组列表,数组的长度可以不同,则使用List<object[]>

List<object[]> l = new List<object[]>();
l.Add(calcul_resporderbyact(responsable,v));

Or you could use a jagged array : 或者您可以使用锯齿数组

object[][] l = new object[length2][];
l[i] = calcul_resporderbyact(responsable,v);

In C# there are jagged arrays and multidimensional arrays . 在C#中,有锯齿状数组多维数组 In your example you seem to be mixing up the two. 在您的示例中,您似乎混淆了两者。

Jagged arrays are created this way, and you'll have to construct each "sub-array" individually: 锯齿状数组是用这种方式创建的,您必须分别构造每个“子数组”:

object[][] obj = new object[10][];
obj[0] = new object[10];
obj[1] = new object[10];
...

Multidimensional arrays on the other hand: 另一方面,多维数组:

object[,] obj = new object[10,10];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM