I have the following, which creates a list of arrays:

        static List<string[]> ReadFileIntoList(string fileName)
        {
            List<string[]> parsedData = new List<string[]>();
            string fullLine;
            string[] row;

            try
            {
                StreamReader sr = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read));
                while ((fullLine = sr.ReadLine()) != null)
                {
                    row = fullLine.Split('\t');
                    parsedData.Add(row);
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Message);
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Yellow;
            }

            return parsedData;
        }

Once this list is created I need to add one additional element to the end of each array within the list and that one additional element will be coming from another list of floating point values; how can I do that?

Recommended Answers

All 3 Replies

There are many ways to do this

foreach (String[] arr in parsedData) {
    // add to your string array here
}

// or you can

for (int i = 0; i < parsedData.Count; i++) {
   parsedData[i] ... // this is the string array, add to it
}

Without knowing more about what you mean by 'adding to the array' and what exactly you want to add to the array, there isn't much more I can show you.

try
{
StreamReader sr = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read));
while ((fullLine = sr.ReadLine()) != null)
{
row = fullLine.Split('\t');
parsedData.Add(row);
}
sr.Close();
//define a string[] of your choice or the string that you want, ex string[] rowAdditional,
parsedData.Add(rowAdditiona);
}

I suppose this should be what you want, though am not sure, like momerath said, be more specific with what you want.

You could, of course, fake it out by making it a

List<List<string>>
// calling the .Add() method on each inner list

and return it as a

 List<string[]>
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.