diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs index 5a5a145..25b7fec 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs @@ -24,14 +24,14 @@ public abstract class AbstractCompany _collection.SetMaxCount = GetMaxCount; } - public static bool operator +(AbstractCompany company, DrawningBoat boat) + public static int operator +(AbstractCompany company, DrawningBoat boat) { - return company._collection?.Insert(boat) ?? false; + return company._collection?.Insert(boat) ?? -1; } - public static bool operator -(AbstractCompany company, int position) + public static DrawningBoat? operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection?.Remove(position); } public DrawningBoat? GetRandomObject() diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs index dc39bc6..0134704 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -10,9 +10,9 @@ public interface ICollectionGenericObjects where T : class { int Count { get; } int SetMaxCount { set; } - bool Insert(T obj); - bool Insert(T obj, int position); - bool Remove(int position); + int Insert(T obj); + int Insert(T obj, int position); + T? Remove(int position); T? Get(int position); } diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs index 2e8965a..64274ba 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs @@ -25,7 +25,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c public MassiveGenericObjects() { _collection = Array.Empty(); - } + } public T? Get(int position) { //todo @@ -36,7 +36,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c return null; } - public bool Insert(T obj) + public int Insert(T obj) { //todo for (int i = 0; i < Count; i++) @@ -44,19 +44,19 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } - return false; + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { //todo if (!(position > 0 && position < _collection.Length)) { - return false; + return -1; } if (_collection[position] == null) @@ -68,7 +68,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } @@ -77,22 +77,23 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } } - return false; + return -1; } - public bool Remove(int position) + public T? Remove(int position) { if (!(position >= 0 && position < _collection.Length) || _collection[position] == null ) { - return false; + return null; } + T? deletedElement = _collection[position]; _collection[position] = null; - return true; + return deletedElement; } } diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs index 37f6cfc..c253d60 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs @@ -52,7 +52,7 @@ public partial class FormBoatCollection : Form return; } - if (_company + drawningBoat) + if (_company + drawningBoat != -1) { MessageBox.Show(("Объект добавлен")); pictureBox.Image = _company.Show(); @@ -100,7 +100,7 @@ public partial class FormBoatCollection : Form } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos) + if (_company - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show();