JNW JNW - 4 months ago 22
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:


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 Source

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

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

Remove the 's'.