diff --git a/SelfPropelledArtilleryUnit.Basic/SelfPropelledArtilleryUnit.Basic/SetGeneric.cs b/SelfPropelledArtilleryUnit.Basic/SelfPropelledArtilleryUnit.Basic/SetGeneric.cs index 7b1a80e..0a76b6d 100644 --- a/SelfPropelledArtilleryUnit.Basic/SelfPropelledArtilleryUnit.Basic/SetGeneric.cs +++ b/SelfPropelledArtilleryUnit.Basic/SelfPropelledArtilleryUnit.Basic/SetGeneric.cs @@ -23,15 +23,16 @@ namespace SelfPropelledArtilleryUnit.Basic } public bool Insert(T MilitaryUnit, IEqualityComparer? equal = null) { - if (places.Count == maxCount) - return false; - Insert(MilitaryUnit, 0); - return true; + return Insert(MilitaryUnit, 0, equal); } public bool Insert(T MilitaryUnit, int index, IEqualityComparer? equal = null) { if (!(index >= 0 && index <= Count && places.Count < maxCount)) return false; + if (places.Count == maxCount) + throw new StorageOverflowException(index); + if (equal != null && places.Contains(MilitaryUnit, equal)) + throw new ArgumentException("Добавленный объект присутствует в коллекции"); places.Insert(index, MilitaryUnit); return true; }