0

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 by peter_budo: Correcting code tags, should be [code] your code here [/code]

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by sknake
Featured Replies
  • 1
    ddanbe 2,525   7 Years Ago

    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?" Read More

0

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

from textfile.

1

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 by ddanbe: n/a

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.