JNW JNW - 18 days ago 7
C# Question

Reading content from text file c sharp

I have written a small program to read line from a text but facing a problem when getting the output. As I just get the following:

System.String[]
System.String[]
System.String[]


instead of having the content of my text file. Here is the written loop:

string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Engineer\Desktop\MyFile.txt");
foreach(string line in lines)
{
console.WriteLine("\t"+ lines);
}

Amy Amy
Answer

In each iteration of the loop, you're writing the array of lines to the output.

                            ▼
console.WriteLine("\t"+ lines);

Remove the 's'.