Добавление и удаление - код дублируется C#
Не принимают работу. Помогите решить.
static void Add(ref string[] fio, ref string[] position)
{
string[] tempFio = new string[fio.Length + 1];
string[] tempPosition = new string[position.Length + 1];
Console.WriteLine("Введите ФИО: ");
string enterFio = Console.ReadLine();
tempFio[tempFio.Length - 1] = enterFio;
Console.WriteLine("Введите должность: ");
string enterPosition = Console.ReadLine();
tempPosition[tempPosition.Length - 1] = enterPosition;
for (int i = 0; i < fio.Length; i++)
{
tempFio[i] = fio[i];
tempPosition[i] = position[i];
}
fio = tempFio;
position = tempPosition;
Console.WriteLine();
}
static void Remove(ref string[] fio, ref string[] position)
{
string[] tempRemoveFio = new string[fio.Length - 1];
string[] tempRemovePosition = new string[position.Length - 1];
int id = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
if (tempRemoveFio.Length >= id)
{
for (int i = 0; i < tempRemoveFio.Length; i++)
{
if (i < id)
{
tempRemoveFio[i] = fio[i];
tempRemovePosition[i] = position[i];
}
else
{
tempRemoveFio[i] = fio[i + 1];
tempRemovePosition[i] = position[i + 1];
}
}
fio = tempRemoveFio;
position = tempRemovePosition;
Console.WriteLine($"Вы удалили досье под номером - {id}");
}
else
{
Console.WriteLine($"Досье под номером {id} не существует.");
}
Console.WriteLine();
}