Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- public class Sort
- {
- public static bool CheckCommand(string command)
- {
- switch (command)
- {
- case "sort":
- return true;
- case "Sort":
- Console.WriteLine("I don't know this command, sorry to say that. Is there a chance you meant 'sort'?");
- return false;
- default:
- Console.WriteLine("I don't know this command, sorry to say that. And I have no idea what you meant...");
- return false;
- }
- }
- public static List<String> ReadFile(string name)
- {
- List<String> lines = new List<String>();
- try
- {
- foreach (string line in File.ReadLines(name))
- {
- lines.Add(line);
- }
- }
- catch (FileNotFoundException)
- {
- Console.WriteLine("I am so sorry to say, but I cannot find such file. I know this might be very difficult," +
- " but please check if you have entered the name correctly. I believe in you.");
- }
- return lines;
- }
- public static void Main(string[] args)
- {
- var command = Console.ReadLine();
- String[] flags = command.Split(" ");
- if(!CheckCommand(flags[0])) return;
- var fileName = flags[^1];
- var linesArray = ReadFile(fileName);
- linesArray.Sort();
- foreach (var line in linesArray)
- {
- Console.WriteLine(line);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment