JNW JNW - 1 year ago 48
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'.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download