c# - Dynamic multidimensional Arrays (Lists?) -
from reading online, i've seen answers solving dynamic arrays such use list. i'm bit confused how perform list operations on multidimensional array. maybe if can understand how implement piece of code such below, i'd able grasp them better.
public void class class1(){ string[,] array; public void arrfunction() { array=new string[rand1,rand2]; int rand1=somerandnum; int rand2=somerandnum2; for(int i=0; i<rand1; i++){ for(int j=0; j<rand2; j++){ array[i][j]=i*j; } } }
your method work fine, need declare , initialize rand1
, rand2
variables before using them, , access array correctly:
public void arrfunction() { int rand1=somerandnum; int rand2=somerandnum2; array=new string[rand1,rand2]; // don't use these until they're set for(int i=0; i<rand1; i++){ for(int j=0; j<rand2; j++){ array[i, j]=i*j; // use [i, j], not [i][j] } } }
also, can't initialize array string:
// gets initialized in method string[,] array; // ="";
Comments
Post a Comment