Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace Databases
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Initial variables
- bool flag = true;
- string name;
- //Reading from the file and putting into list seperated by '\n' so everyline
- string filename = @"testdoc.txt";
- string text = Readfile(filename);
- List<string> Nameslist = new List<string>();
- Nameslist = text.Split('\n').ToList();
- //Resets the file
- WriteFile(filename, "");
- //Keeps the loop running until flag != true
- while (flag)
- {
- //'Q' is halt condition
- Console.WriteLine("Enter the entity or enter 'Q' to quit");
- name = Console.ReadLine();
- if (name == "Q")
- {
- //End decision
- Nameslist.Sort();
- for (int i = 0;i<Nameslist.Count();i++)
- {
- AppendFile(filename, Nameslist[i]);
- }
- flag = false;
- } else
- {
- //Add to list devision
- Nameslist.Add(name);
- }
- }
- }
- static void AppendFile(string filename , string Text)
- {
- StreamWriter File = new StreamWriter(filename, true);
- File.WriteLine("\n"+Text);
- File.Close();
- }
- static void WriteFile(string filename, string Text)
- {
- StreamWriter File = new StreamWriter(filename);
- File.Write(Text);
- File.Close();
- }
- static string Readfile(string filename)
- {
- StreamReader File = new StreamReader(filename);
- string temp = File.ReadToEnd();
- File.Close();
- return (temp);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment