Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace C_sharp_Light
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] name = new string[0];
- string[] post = new string[0];
- bool isOpen = true;
- while (isOpen)
- {
- Console.WriteLine("Программа досье\nУправление:\n1) Добавить досье\n2) Вывести все досье\n3) Удалить досье по номеру(не индекс массива)\n4) Поиск по фамилии \n0) Выход\n\n");
- ConsoleKeyInfo key = Console.ReadKey();
- Console.Clear();
- switch (key.Key)
- {
- case ConsoleKey.D1:
- AddDossier(ref name, ref post);
- break;
- case ConsoleKey.D2:
- WriteAllDossier(name, post);
- break;
- case ConsoleKey.D3:
- DeletDossier(ref name, ref post);
- break;
- case ConsoleKey.D4:
- SearchByLastName(name);
- break;
- case ConsoleKey.D0:
- isOpen = false;
- break;
- }
- }
- }
- static void AddDossier(ref string[] name, ref string[] post)
- {
- Console.Write("Введите имя = ");
- string nameTemp = Console.ReadLine();
- Console.Write("Введите должность = ");
- string postTemp = Console.ReadLine();
- name = ResizeArray(name);
- post = ResizeArray(post);
- name[name.Length - 1] = nameTemp;
- post[post.Length - 1] = postTemp;
- Console.WriteLine("\n\nУдачное добавление!");
- Console.ReadKey();
- Console.Clear();
- }
- static void WriteAllDossier(string[] name, string[] post)
- {
- for (int i = 0; i < name.Length; i++)
- {
- Console.Write($"{i + 1} - ");
- Console.SetCursorPosition(6, i);
- Console.Write($"Имя: {name[i]}");
- Console.SetCursorPosition(24, i);
- Console.Write($"Должность: {post[i]}");
- Console.WriteLine();
- }
- Console.ReadKey();
- Console.Clear();
- }
- static void SearchByLastName(string[] name)
- {
- Console.Clear();
- Console.Write("Введите фамилию: ");
- string searchName = Console.ReadLine();
- searchName.ToLower();
- Console.WriteLine("\n\n");
- int[] result = new int[0];
- for (int i = 0; i < name.Length; i++)
- {
- string temp = name[i];
- temp.ToLower();
- if (temp == searchName)
- {
- result = ResizeArray(result);
- result[result.Length - 1] = i;
- }
- }
- Console.WriteLine("Следующие номера имеют искоемую фамилю:");
- for (int i = 0; i < result.Length; i++)
- {
- Console.Write($"{i} ");
- if (i % 3 == 0 && i != 0)
- Console.WriteLine();
- }
- Console.ReadKey();
- Console.Clear();
- }
- static void DeletDossier(ref string[] name, ref string[] post)
- {
- Console.Clear();
- Console.Write("Введите номер для удаления: ");
- int number = Convert.ToInt32(Console.ReadLine());
- number--;
- name = ResizeArray(name, number);
- post = ResizeArray(post, number);
- Console.Clear();
- }
- static public string[] ResizeArray(string[] array, int number)
- {
- string[] tempArray = new string[array.Length - 1];
- for (int i = 0; i < array.Length; i++)
- {
- if (i != number)
- tempArray[i] = array[i];
- }
- return tempArray;
- }
- static public string[] ResizeArray(string[] array)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- return tempArray;
- }
- static public int[] ResizeArray(int[] array)
- {
- int[] tempArray = new int[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- return tempArray;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement