0

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?

4
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by thines01
0

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.

0

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.

0

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