Free for PREMIUM members
Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium
public static void Main()
List<string> myFileInArray = new List<string>();
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
catch (Exception e)
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Open in new window
We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!