Read all lines from a text file in CSharp
Description
The following code shows how to real all lines from a text file.
Example
using System;/*from www .j a v a 2s.c o m*/
using System.Collections.Generic;
using System.Text;
using System.IO;
class MainClass
{
static void Main(string[] args)
{
StreamWriter writer = new StreamWriter(@"c:\myfile.txt");
for (int i = 0; i < 3; i++)
{
writer.Write(i.ToString());
}
writer.Flush();
writer.Close();
foreach (string line in File.ReadAllLines(@"c:\myfile.txt"))
{
Console.WriteLine(line);
}
}
}