3

I use an array of array :

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

Now, what i want is to insert a new array into of[][], I try this :

 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 ??

9
  • 1
    start by saying what 'dont work' means, then what exactly are you trying to do? Commented Sep 18, 2013 at 6:50
  • It should be object[,] of =new object[lenght2,]; Commented Sep 18, 2013 at 6:51
  • 1
    @Anirudh object[,] of =new object[lenght2,]; won't compile, you need to specify both lenghts like object[,] of =new object[lenght1,lenght2]; Commented Sep 18, 2013 at 6:52
  • See stackoverflow.com/q/11330990 Commented Sep 18, 2013 at 6:55
  • Instead of creating of array of arrays You can try using List<object[]>. Commented Sep 18, 2013 at 6:55

3 Answers 3

5

You have couple of mistakes, in your code 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.

Sign up to request clarification or add additional context in comments.

Comments

2

In C# there are jagged arrays and multidimensional arrays. 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];

Comments

1

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[]> 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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.