diff --git a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs index 61b285a..1aac3c3 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.cs @@ -106,7 +106,7 @@ namespace AntiAircraftGun FormAntiAirCraftGun form = new(); if (form.ShowDialog() == DialogResult.OK) { - if ((obj + form.SelectedZenit)==1) + if (obj + form.SelectedZenit) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowZenits(); diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs index 583b694..2df4441 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs @@ -51,11 +51,11 @@ namespace AntiAircraftGun.Generics /// /// /// - public static int operator +(AntiAirCraftGunGenericCollection collect, T? obj) + public static bool operator +(AntiAirCraftGunGenericCollection collect, T? obj) { if (obj == null) - return -1; - return collect?._collection.Insert(obj) ?? -1; + return false; + return collect?._collection.Insert(obj) ?? false; } /// /// Перегрузка оператора вычитания @@ -63,12 +63,12 @@ namespace AntiAircraftGun.Generics /// /// /// - public static bool operator -(AntiAirCraftGunGenericCollection collect, int pos) + public static T? operator -(AntiAirCraftGunGenericCollection collect, int pos) { - T? obj = collect._collection.Get(pos); - if (obj != null) - return collect._collection.Remove(pos); - return false; + T? obj = collect._collection.Get(pos); + if (obj != null) + collect._collection.Remove(pos); + return obj; } /// diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs index e63218e..abcfa88 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs @@ -35,21 +35,20 @@ namespace AntiAircraftGun.Generics /// /// Добавляемый автомобиль /// - public int Insert(T car) + public bool Insert(T car) { if (_places.Count == _maxCount) - return -1; + return false; Insert(car, 0); - return 1; - + return true; } - public int Insert(T car, int position) + public bool Insert(T car, int position) { if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) - return -1; + return false; _places.Insert(position, car); - return 1; + return true; } /// @@ -63,8 +62,8 @@ namespace AntiAircraftGun.Generics if (position < 0 || position >= Count) return false; - // Удаление объекта из массива, присвоив элементу массива значение null - _places[position] = null; + + _places.RemoveAt(position); return true; } /// @@ -76,33 +75,16 @@ namespace AntiAircraftGun.Generics { get { - // TODO: Проверить позицию - if (position < 0 || position >= Count) - { - MessageBox.Show("Индекс выходит за пределы диапазона"); + if (!(position >= 0 && position < Count)) return null; - } return _places[position]; } set { - // TODO: Проверить позицию - if (position < 0 || position >= Count) - { - MessageBox.Show("Индекс выходит за пределы диапазона"); + if (!(position >= 0 && position < Count && _places.Count < _maxCount)) return; - } - // TODO: Проверить наличие доступных слотов в списке - if (_places.Count < _maxCount) - { - // Вставить на указанную позицию - _places.Insert(position, value); - } - else - { - MessageBox.Show("Список уже заполнен"); - return; - } + _places.Insert(position, value); + return; } } ///