Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express one dimension of 2d array as new array

Tags:

c#

I have a 2d array a[3,3]. How can I express one dimension as a new array and pass it to some function?

int[,] a = new int[3,3];

a[0,0] = 1;

...

string b = concatenate(a[0]);     // where concatenate is a function
                                  // take a one dimension array as param

Also, can I create a 65000x65000 array with C#? I got some "out of memory" error.

like image 251
Mavershang Avatar asked Jan 23 '26 04:01

Mavershang


2 Answers

The easiest way to handle this is to create a jagged array

int[][] i = new int[3][];

that way:

string b = concatenate(i[0]); will work.

To your second question you will run into issues with the LOH with objects approaching that size. This is probably not your problem though. I would look here as to a possible explanation as to why.

like image 172
kemiller2002 Avatar answered Jan 24 '26 20:01

kemiller2002


You will need to use jagged arrays.

int[][] a = new int[3][]
a[0] = new int[3];
a[1] = new int[3];
a[2] = new int[3];
a[0][0] = 1;
string b = concatentate(a[0]);

Also, creating a 65000x65000 array would result in 65000^2 = 4225000000 slots (or about 16GB or data) so it is no wonder that you are getting an OutOfMemoryException.

like image 30
Brian Gideon Avatar answered Jan 24 '26 19:01

Brian Gideon