Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] secondName = new string[0];
- string[] position = new string[0];
- string userInputName, userInputPosition;
- string userInput;
- bool isContinue = true;
- int inputNumberDossier;
- while (isContinue)
- {
- WriteColored("\nНажмите любую клавишу...");
- Console.ReadKey();
- Console.Clear();
- WriteColored("Меню:\n1)Добавить досье\n2)Вывести все досье\n3)Удалить досье\n4)Поиск по фамилии\n5.Выход\n");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- WriteColored("\nВведите фамилию: ");
- userInputName = Console.ReadLine();
- WriteColored("\nВведите должность: ");
- userInputPosition = Console.ReadLine();
- secondName = MakeNewDossierArray(secondName, userInputName);
- position = MakeNewDossierArray(position, userInputPosition);
- WriteColored("Досье добавленно!", ConsoleColor.Green);
- break;
- case "2":
- if (secondName.Length > 0)
- {
- for (int i = 0; i < secondName.Length; i++)
- WriteColored($"{i + 1}. {secondName[i]} - {position[i]}\n", ConsoleColor.Green);
- }
- else
- {
- WriteColored("Здесь пока ничего нет:(", ConsoleColor.Red);
- }
- break;
- case "3":
- WriteColored("\nВведите номер досье которого нужно удалить: ");
- userInput = Console.ReadLine();
- try
- {
- inputNumberDossier = Convert.ToInt32(userInput);
- if ( inputNumberDossier <= secondName.Length + 1 && inputNumberDossier >= 1)
- {
- secondName = RemoveDossier(secondName, Convert.ToInt32(userInput) - 1);
- position = RemoveDossier(position, Convert.ToInt32(userInput) - 1);
- WriteColored("Досье удалено!", ConsoleColor.Green);
- }
- else
- {
- WriteColored("Такого досье не существует!", ConsoleColor.Red);
- }
- }
- catch (Exception)
- {
- WriteColored("Такого досье не существует!", ConsoleColor.Red);
- }
- break;
- case "4":
- WriteColored("\nдля поиска досье - введите фамилию: ");
- userInput = Console.ReadLine();
- FindIndexDossier(secondName, userInput);
- break;
- case "5":
- isContinue = false;
- break;
- default:
- WriteColored("\nТы ошибся - пиши цифрами выбор функции программы\n", ConsoleColor.Red);
- break;
- }
- }
- }
- static private void WriteColored(string text, ConsoleColor color = ConsoleColor.Yellow)
- {
- Console.ForegroundColor = color;
- Console.Write(text);
- Console.ResetColor();
- }
- static private string[] ResizeArray(string[] array)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- tempArray[i] = array[i];
- return array = tempArray;
- }
- static private string[] MakeNewDossierArray(string[] arrayDossier, string userInput)
- {
- arrayDossier = ResizeArray(arrayDossier);
- arrayDossier[arrayDossier.Length - 1] = userInput;
- return arrayDossier;
- }
- static private string[] RemoveDossier(string[] array, int index)
- {
- string[] newArray = new string[array.Length - 1];
- for (int i = 0; i < index; i++)
- newArray[i] = array[i];
- for (int i = index + 1; i < array.Length; i++)
- newArray[i - 1] = array[i];
- return array = newArray;
- }
- static private void FindIndexDossier(string[] secondName, string userInput)
- {
- bool isFind = false;
- for (int i = 0; i < secondName.Length; i++)
- {
- if (secondName[i] == userInput)
- {
- WriteColored($"Данное досье находится на строке: {i + 1}", ConsoleColor.Green);
- isFind = true;
- break;
- }
- }
- if (!isFind)
- {
- WriteColored("Не удалось найти досье по фамилии:(", ConsoleColor.Red);
- }
- }
- }
- }
RAW Paste Data