c# - can a string array go past 111? -


i trying make array gather lines in files in directory, thought had finally, when string array gets entry 111 crashes indexoutofrangeexception

string[] wordlist = new string[adjectivelistlength]; console.writeline("length .. " + adjectivelistlength); console.writeline("string length .. " + wordlist.length); int o = 0; (int = 0; < fileentries.length; i++) {     wordlist = file.readalllines(fileentries[i]);     foreach (string s in wordlist)     {         console.writeline(s + " .. " + + " .. " + o);         wordlist[o] = s;         //o += 1;     } } 

the exception points int commented out when error, i've been trying few hours , i've gotten far feel i'm 1 inch finish line can't figure out what's going on.

the best way task use list<string> used without knowing beforehand length of each file in fileentries array

list<string> wordlist = null; (int = 0; < fileentries.length; i++) {     wordlist = file.readlines(fileentries[i]).tolist();     foreach (string s in wordlist)         console.writeline(s + " .. " + i);      // if want line number use normal for..loop , c# 6.0 syntax     for(int o = 0; o < wordlist.count(); o++)         console.writeline($"file:{i} @ line {o} ..{wordlist[o]}");    } 

if want use arrays don't need dimension array because file.readalllines creates array you

string[] wordlist = null; (int = 0; < fileentries.length; i++) {     wordlist = file.readalllines(fileentries[i]);     foreach (string s in wordlist)         console.writeline(s + " .. " + i); } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -