From ca917f05112283c9fe8a3167d39c418c47d6e857 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 3 Oct 2022 16:17:27 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=9B=D0=B0=D0=B13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Locomotive/FormMapWithSetLocomotives.cs | 4 ++-- .../MapWithSetLocomotivesGeneric.cs | 4 ++-- .../Locomotive/SetLocomotivesGeneric.cs | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs index 55ec098..34f705f 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -55,7 +55,7 @@ namespace Locomotive if (form.ShowDialog() == DialogResult.OK) { DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); - if (_mapLocomotivesCollectionGeneric + locomotive) + if (_mapLocomotivesCollectionGeneric + locomotive != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); @@ -78,7 +78,7 @@ namespace Locomotive return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapLocomotivesCollectionGeneric - pos) + if (_mapLocomotivesCollectionGeneric - pos is not null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); diff --git a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs index 3a9f8cc..71eaad3 100644 --- a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs @@ -33,12 +33,12 @@ namespace Locomotive _map = map; } /// Перегрузка оператора сложения - public static bool operator +(MapWithSetLocomotivesGeneric map, T locomotive) + public static int operator +(MapWithSetLocomotivesGeneric map, T locomotive) { return map._setLocomotives.Insert(locomotive); } /// Перегрузка оператора вычитания - public static bool operator -(MapWithSetLocomotivesGeneric map, int position) + public static T operator -(MapWithSetLocomotivesGeneric map, int position) { return map._setLocomotives.Remove(position); } diff --git a/Locomotive/Locomotive/SetLocomotivesGeneric.cs b/Locomotive/Locomotive/SetLocomotivesGeneric.cs index 1397e44..5deb455 100644 --- a/Locomotive/Locomotive/SetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/SetLocomotivesGeneric.cs @@ -19,19 +19,19 @@ namespace Locomotive _places = new T[count]; } /// Добавление объекта в набор - public bool Insert(T locomotive) + public int Insert(T locomotive) { return Insert(locomotive, 0); } /// Добавление объекта в набор на конкретную позицию - public bool Insert(T locomotive, int position) + public int Insert(T locomotive, int position) { - if (position >= _places.Length|| position < 0) return false; + if (position >= _places.Length|| position < 0) return -1; if (_places[position] == null) { _places[position] = locomotive; - return true; + return position; } int emptyEl = -1; @@ -47,7 +47,7 @@ namespace Locomotive if (emptyEl == -1) { - return false; + return -1; } for (int i = emptyEl; i > position; i--) @@ -55,14 +55,15 @@ namespace Locomotive _places[i] = _places[i - 1]; } _places[position] = locomotive; - return true; + return position; } /// Удаление объекта из набора с конкретной позиции - public bool Remove(int position) + public T Remove(int position) { - if (position >= _places.Length || position < 0) return false; + if (position >= _places.Length || position < 0) return null; + T result = _places[position]; _places[position] = null; - return true; + return result; } /// Получение объекта из набора по позиции public T Get(int position)