- Home /
Question by
isopoly23 · Jan 14, 2018 at 06:47 PM ·
listfilestreamtxtstreamreader
Im trying to read and split a txt file, then place them into a list, When I tested it, it only had added one entry to the list. Can you guys help me understand whats going wrong ? Thank you
private void ReadDropList ()
{
Dropline = " ";
fs1 = new FileStream (dropPath, FileMode.Open);
Reader = new StreamReader (fs1, true);
Dropline = Reader.ReadToEnd ();
string[] entries = Dropline.Split (SplitChar, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in entries) {
Droppers.Add (item);
}
Reader.Close ();
}
Comment
Answer by OrionGamesInc · Jan 16, 2018 at 05:49 PM
This may be another solution rather than a foreach loop.
for (int i = 0; i < Droppers.Length; i++) {
if(i >= Droppers.Length){
break;
}
Droppers.Add(item);
Debug.Log ("Adding new item.");
}
This makes no sense. Droppers is his target list. Iterating over the list and adding "item" to the same list makes no sense.