Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ReadFile
- {
- class FromLocalComputer
- {
- static void Main(string[] args)
- {
- // Fix the encoding to UTF8 if work with cyrillic characters
- Console.OutputEncoding = Encoding.UTF8;
- const string course = "Въведение в програмирането";
- // Take the full path to the file
- string file = @"C:\Users\Republic Of Gamers\Desktop\TEMPORARY\students.txt";
- // Use ADT (Abstract Data Type) to hold the data from the file
- List<string> studentList = new List<string>();
- #region Read the file
- // Create object who will read the file & pass its constructor path to the file
- StreamReader fileReader = new StreamReader(file);
- // Open connection for the data stream
- using (fileReader)
- {
- // Create variable in wich we will hold the line who's going to be read from the file & start reading
- string currentLine = fileReader.ReadLine();
- // Pass condition in who the file contains only empty lines & use it ti understand when there is no tex to be readed anymore
- while (currentLine != null)
- {
- // If there is a data - add it to the list
- studentList.Add(currentLine);
- // Print the current line data
- Console.WriteLine("Student name : {0} \nCourse : {1}", currentLine, course);
- Console.WriteLine("----------------------------------------");
- // Read the next line of the file
- currentLine = fileReader.ReadLine();
- }
- }
- #endregion END Read the file
- #region Print data from the studentList
- Console.WriteLine("888888888888888888888888888888888888888888888888");
- Console.WriteLine();
- // See how much students are
- Console.WriteLine("There are {0} students in the group & names are: ", studentList.Count);
- studentList.Sort();
- // Create random generator just for fun
- Random rnd = new Random();
- foreach (string studentName in studentList)
- {
- // Generate fake ID
- int rndNumber = rnd.Next(byte.MinValue, byte.MaxValue);
- // Print the new data
- Console.WriteLine("{0} \nФакултетен номер: {1}", studentName, rndNumber);
- Console.WriteLine("..............................................................");
- }
- #endregion
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement