This commit is contained in:
Илья Федотов 2023-12-27 22:37:02 +04:00
parent c0a2c582e8
commit 977c6de6f6

View File

@ -23,15 +23,16 @@ namespace SelfPropelledArtilleryUnit.Basic
}
public bool Insert(T MilitaryUnit, IEqualityComparer<T>? 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<T>? 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;
}