user1199526
user1199526

Reputation: 19

Address a single row of a 2-dimensional array?

Is there any way in c# to address a single row of a 2-dimensional array?

I want to be able to pass one-dimension of a 2 dimensional array as a parameter and sometimes I want to pass the whole 2-dimentional array.

Upvotes: 1

Views: 249

Answers (1)

Oded
Oded

Reputation: 499132

You can use jagged arrays.

Example based on the code in Jagged Arrays (C# Programming Guide):

int[][] jaggedArray = new int[3][];

jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];

// To pass the whole thing, use jaggedArray
// To pass one of the inner arrays, use jaggedArray[index]

Upvotes: 1

Related Questions