Search code examples
c#fileiostreamreader

Is it possible to read multiple files at once in C#?


Is it possible to read multiple files at once in C#? I have got this so far.

for (int i=1; i<Foo.number_of_files+1;i++)
{
    StreamReader aa= new StreamReader (@"realtime_" + Foo.main_id + "_" + i + ".txt");
}

I know that I need to create a unique StreamReader name for each file, how to do this? Can I put the StreamReader to a list? Sort of like list of StreamReaders ? What is the best way to read multiple files at once?


Solution

  • You probably want:

    var readers = new List<StreamReader> ();
    
    for (...)
    {
       var aa = new StreamReader(@"realtime_" + Foo.main_id + "_" + i + ".txt"); 
       readers.Add(aa);
    }