View difference between Paste ID: SUZXfymV and C26sWULh
SHOW: | | - or go back to the newest paste.
1
using System;
2
3
namespace C_sharp_Light
4
{
5
    class Program
6
    {
7
        static void Main(string[] args)
8
        {
9-
            
9+
            string[] name = new string[0];
10
            string[] post = new string[0];
11
            bool isOpen = true;
12
            while (isOpen)
13
            {
14
                Console.WriteLine("Программа досье\nУправление:\n1) Добавить досье\n2) Вывести все досье\n3) Удалить досье по номеру(не индекс массива)\n4) Поиск по фамилии \n0) Выход\n\n");
15
                ConsoleKeyInfo key = Console.ReadKey();
16
                Console.Clear();
17
                switch (key.Key)
18
                {
19
                    case ConsoleKey.D1:
20
                        AddDossier(ref name, ref post);
21
                        break;
22
                    case ConsoleKey.D2:
23
                        WriteAllDossier(name, post);
24
                        break;
25
                    case ConsoleKey.D3:
26
                        DeletDossier(ref name, ref post);
27
                        break;
28
                    case ConsoleKey.D4:
29
                        SearchByLastName(name);
30
                        break;
31
                    case ConsoleKey.D0:
32
                        isOpen = false;
33
                        break;
34
                }
35
            }
36
        }
37
        static void AddDossier(ref string[] name, ref string[] post)
38
        {
39
            Console.Write("Введите имя = ");
40
            string nameTemp = Console.ReadLine();
41
            Console.Write("Введите должность = ");
42
            string postTemp = Console.ReadLine();
43
44
            name = ResizeArray(name);
45
            post = ResizeArray(post);
46
47
            name[name.Length - 1] = nameTemp;
48
            post[post.Length - 1] = postTemp;
49
            Console.WriteLine("\n\nУдачное добавление!");
50
            Console.ReadKey();
51
            Console.Clear();
52
        }
53
        static void WriteAllDossier(string[] name, string[] post)
54
        {
55
            for (int i = 0; i < name.Length; i++)
56
            {
57
                Console.Write($"{i + 1} - ");
58
                Console.SetCursorPosition(6, i);
59
                Console.Write($"Имя: {name[i]}");
60
                Console.SetCursorPosition(24, i);
61
                Console.Write($"Должность: {post[i]}");
62
                Console.WriteLine();
63
            }
64
            Console.ReadKey();
65
            Console.Clear();
66
        }
67
        static void SearchByLastName(string[] name)
68
        {
69
            Console.Clear();
70
            Console.Write("Введите фамилию: ");
71
            string searchName = Console.ReadLine();
72
            searchName.ToLower();
73
            Console.WriteLine("\n\n");
74
75
            int[] result = new int[0];
76
77
            for (int i = 0; i < name.Length; i++)
78
            {
79
                string temp = name[i];
80
                temp.ToLower();
81
                if (temp == searchName)
82
                {
83
                    result = ResizeArray(result);
84
                    result[result.Length - 1] = i;
85
                }
86
            }
87
            Console.WriteLine("Следующие номера имеют искоемую фамилю:");
88
            for (int i = 0; i < result.Length; i++)
89
            {
90
                Console.Write($"{i}  ");
91
                if (i % 3 == 0 && i != 0)
92
                    Console.WriteLine();
93
            }
94
            Console.ReadKey();
95
            Console.Clear();
96
        }
97
        static void DeletDossier(ref string[] name, ref string[] post)
98
        {
99
            Console.Clear();
100
            Console.Write("Введите номер для удаления: ");
101
            int number = Convert.ToInt32(Console.ReadLine());
102
            number--;
103
            name = ResizeArray(name, number);
104
            post = ResizeArray(post, number);
105
            Console.Clear();
106
        }
107
        static public string[] ResizeArray(string[] array, int number)
108
        {
109
            string[] tempArray = new string[array.Length - 1];
110
            for (int i = 0; i < array.Length; i++)
111
            {
112
                if (i != number)
113
                    tempArray[i] = array[i];
114
            }
115
            return tempArray;
116
        }
117
        static public string[] ResizeArray(string[] array)
118
        {
119
            string[] tempArray = new string[array.Length + 1];
120
            for (int i = 0; i < array.Length; i++)
121
            {
122
                tempArray[i] = array[i];
123
            }
124
            return tempArray;
125
        }
126
        static public int[] ResizeArray(int[] array)
127
        {
128
            int[] tempArray = new int[array.Length + 1];
129
            for (int i = 0; i < array.Length; i++)
130
            {
131
                tempArray[i] = array[i];
132
            }
133
            return tempArray;
134
        }
135
    }
136
}