class ReadFromFile
{
static void Main()
{
// Read the file as one string.
string text = System.IO.File.ReadAllText(@"c:\test.txt");
// Display the file contents to the console.
System.Console.WriteLine("Contents of test.txt = {0}", text);
// Read the file lines into a string array.
string[] lines = System.IO.File.ReadAllLines(@"c:\test2.txt");
System.Console.WriteLine("Contents of test2.txt =:");
foreach (string line in lines)
{
Console.WriteLine("\t" + line);
}
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.