Hi,

I'm trying to read from an Arraylist in C#, I have the following code:

for (int i = 0; i < arraySize; i++)
                {
                    string arrayListInput = inputArrayList[i];
                   ....
                 }

basically I want to read every line from the arraylist to do some computations but apparently the contents of string arrayListInput are remaining "null" how can I read each line from the arraylist and store it as string?

Thanks!

Edited 6 Years Ago by peter_budo: Correcting code tags, should be [code] your code here [/code]

How did you construct your inputArrayList?
From a file? From input via the console?

from textfile.

Yes, but could you show the code you used to do that?
Your answer is the same as saying: "Hey I went for a walk, and now my ArrayList is all null, please tell me how come?"

Edited 6 Years Ago by ddanbe: n/a

Yes, but could you show the code you used to do that?
Your answer is the same as saying: "Hey I went for a walk, and now my ArrayList is all null, please tell me how come?"

StreamReader objReader = new StreamReader(filePath);
                string sLine = "";     
                  while (sLine != null)
                    {
                        sLine = objReader.ReadLine();

                        if (sLine != null)
                        {
                            inputArrayList.Add(sLine);
                            
                        }
                    }//end while
            objReader.Close();

that is the code!

thanks :)

This article has been dead for over six months. Start a new discussion instead.