From ddcceff03f4d8329a1163010d2aca0b8a97e1c6c Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 25 Oct 2023 09:50:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B3=D1=80=D1=83?= =?UTF-8?q?=D0=B7=D0=BA=D0=B0=20=D1=81=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B8=20=D0=B2=D1=8B=D1=87=D0=B8=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Generics/LocomotivesGenericCollection.cs | 19 +++++++++++-------- .../LogicFormLocomotiveCollection.cs | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs index 7e21c74..182f1f0 100644 --- a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs @@ -56,14 +56,17 @@ namespace ProjectElectricLocomotive.Generics /// /// /// - public static bool operator +(LocomotivesGenericCollection collect, T? - obj) + public static int operator +(LocomotivesGenericCollection collect, T? obj) { if (obj == null) { - return false; + return 0; } - return collect?._collection.Insert(obj) ?? false; + if (collect?._collection.Insert(obj) ?? false) + { + return collect._collection.Count; + } + return 0; } /// /// Перегрузка оператора вычитания @@ -71,15 +74,15 @@ namespace ProjectElectricLocomotive.Generics /// /// /// - public static T? operator -(LocomotivesGenericCollection collect, int + public static int operator -(LocomotivesGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); - if (obj != null) + if (obj != null && collect._collection.Remove(pos)) { - collect._collection.Remove(pos); + return collect._collection.Count; } - return obj; + return -1; } /// /// Получение объекта IMoveableObject diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index ca624f5..065adab 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -41,7 +41,7 @@ namespace ProjectElectricLocomotive FormLocomotive form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_locomotives + form.SelectedLocomotive) + if (_locomotives + form.SelectedLocomotive > 0) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = _locomotives.ShowLocomotives(); @@ -66,7 +66,7 @@ namespace ProjectElectricLocomotive return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_locomotives - pos != null) + if (_locomotives - pos != -1) { MessageBox.Show("Объект удален"); pictureBoxCollection.Image = _locomotives.ShowLocomotives();