2
Answers

Passing subarrays as parameter

Ask a question
Carl

Carl

17y
5.8k
1
Dear community,

How do I pass a subarray from a multidimensional array as a parameter to a function?

In c the code would be like:
int array[5][5];
array[3][1]= 3;
dosomething(array[3]); // passes the 4th subarray to the function

Declared as:
void dosomething(int[]);

How will the port to c# look like?

int[][] array= new array[5][5]; // syntax error
int[][] array= new array[5,5]; // compile error: cannot cast [,] implicitely to [][]
int[,] array= new array[5,5];
array[3][1]= 3;
dosomething(array[3]); // compile error, 2 dimensions expected

Can someone help me out?

Thanks,
Carl 

Answers (2)