From 6dcc2b89b7f83d4953df71cc45b068c1b3ee87e2 Mon Sep 17 00:00:00 2001 From: nezui1 Date: Tue, 9 Apr 2024 09:10:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=E2=84=964(1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 3 +++ .../MassiveGenericObjects.cs | 19 +++++++++++++++++-- .../StorageCollection.cs | 12 ++++++++++++ .../FormWarPlaneCollection.cs | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs index cb362ec..f891363 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace ProjectAirFighter.CollectionGenericObjects; +/// +/// Перечисление типов коллекции +/// public enum CollectionType { /// diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs index b398a65..24add23 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs @@ -17,11 +17,26 @@ public class MassiveGenericObjects : ICollectionGenericObjects /// /// Массив объектов, которые хроним /// - private T[] _collection; + private T?[] _collection; public int Count => _collection.Length; - public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + public int SetMaxCount + { + set + { + if (value > 0) + { + if (Count > 0) + { + Array.Resize(ref _collection, value); + } + else { + _collection = new T?[value]; + } + } + } + } /// /// Конструктор diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs index a8a4bdd..cc7d23f 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs @@ -81,4 +81,16 @@ public class StorageCollection return _storages[name]; } } + + public ICollectionGenericObjects? this[int index] + { + get + { + //логика получения объекта + if (index > Keys.Count || index < 0) + return null; + + return _storages[Keys[index]]; + } + } } diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs index 8702bf4..0a9b329 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs @@ -215,7 +215,7 @@ public partial class FormWarPlaneCollection : Form MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; }