I’m trying the following code to read a number of text files into array of string
for (int j = 0; j < paths.Length; j++)
{
StreamReader fs = new StreamReader(paths[j]);
string file_text = fs.ReadToEnd();
textToarray[j] = file_text;
fs.Close();
}
Can I do the same procedure with one time employing of the StreamRreader? is there any better way?
You can use LINQ and
File.ReadAllTextmethods together to do it in a single line of code: