Skip to content

Instantly share code, notes, and snippets.

@DanielFerguson
Last active February 18, 2016 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielFerguson/19d36864f53a1cc6a44d to your computer and use it in GitHub Desktop.
Save DanielFerguson/19d36864f53a1cc6a44d to your computer and use it in GitHub Desktop.
C# Code Notes (Volume 2)
// SYSTEM IO - Reading from a text file (.txt)
// Read the file as one string.
string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteText.txt");
// DISPLAY the file contents to the console. Variable text is a string
System.Console.WriteLine("Contents of WriteText.txt = {0}", text);
// READ each line of the file into a string array. Each element of the array is one line of the file
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines2.txt");
// DISPLAY the file contents by using a foreach loop
System.Console.WriteLine("Contents of WriteLines2.txt = ");
foreach (string line in lines)
{
// Use a tab to indent each line of the file.
Console.WriteLine("\t" + line);
}
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
// PLANS
// Link Navigation / Handling (C#)
// XAML Link
// Linda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment