Why Can't I Assign Value to this Array in c#? -


i'm triying find out way can know users online on app, therefore data i'm saving text file, when try reading line line of text file, want pass array compare data better. here how doing it:

string folder = application.startuppath; string file = "users.txt";  string str; string[] strarray; string[][] data; int rows = 0; streamreader lines = new streamreader(folder + file); while ((str = lines.readline()) != null) {     strarray = str.split('~');     (int = rows; <= rows; i++)     {         (int j = 0; j < strarray.length; j++)         {             data[rows][j] = strarray[j]; // here error         }     }     rows++; } 

as see, declared array of data in before, says can't use cause unassigned.

thanks in advance.

for explanation of error, need jagged arrays. key need initialize both outer array , inner arrays:

int[][] jagged = new int[5][];  // initialized outer array jagged[0] = new int[3];         // initialized inner array 

however, since don't know how many rows need ahead of time, should use list instead:

list<list<string>> data = new list<list<string>>(); while ((str = lines.readline()) != null) {     data.add(str.split('~').tolist()); } 

or, if want single list:

list<string> data = new list<string>(); while ((str = lines.readline()) != null) {     data.addrange(str.split('~')); } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -