Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // View the video tutorial here: https://www.youtube.com/watch?v=HkkcPIZtfxU
- // © Dan Parker 2014 - wangoland@gmail.com
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace Read_from_Text_File
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Define our one and only variable
- string[] names = new string[5];
- // Read the text from the text file, and insert it into the array
- StreamReader SR = new StreamReader(@"names.txt");
- for (int i = 0; i < 5; i++)
- {
- names[i] = SR.ReadLine();
- }
- // Close the text file, so other applications/processes can use it
- SR.Close();
- // Write the array to the Console
- Console.WriteLine("Here are your 5 names from the text file: ");
- for(int i = 0; i < 5; i++)
- {
- Console.WriteLine(names[i]); // Displays the line to the user
- }
- // Pause the application so the user can read the information on the screen
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment