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!

Recommended Answers

All 5 Replies

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

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

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 :)

string[] lines = System.IO.File.ReadAllLines(@"C:\test.txt");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.