read text console c# code example

Example 1: c sharp how to read a text file

// To save the text as one string use 'ReadAllText()'
string text = System.IO.File.ReadAllText(@"C:\filepath\file.txt");
// To save each line seperately in an array use 'ReadAllLines()'
string[] lines = System.IO.File.ReadAllLines(@"C:\filepath\file.txt");

Example 2: c# what is console readline

Console.ReadLine(); ??????
Reads the next line of characters from the standard input stream.
One of the most common uses of the ReadLine method is to pause program 
execution before clearing the console and displaying new information to 
it, or to prompt the user to press the Enter key before terminating the
application.