From b45f27b91db745202c5fab48adf9060c5d06e5d1 Mon Sep 17 00:00:00 2001 From: sardq Date: Thu, 28 Dec 2023 09:44:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=207=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HoistingCrane/HoistingCrane/SetGeneric.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/HoistingCrane/HoistingCrane/SetGeneric.cs b/HoistingCrane/HoistingCrane/SetGeneric.cs index 0472837..c525799 100644 --- a/HoistingCrane/HoistingCrane/SetGeneric.cs +++ b/HoistingCrane/HoistingCrane/SetGeneric.cs @@ -25,6 +25,7 @@ namespace HoistingCrane.Generics if (Count >= _maxCount) throw new StorageOverflowException(Count); _places.Insert(0, crane); + if (_places.Contains(null)) _places.Remove(null); return 0; } public int Insert(T crane, int position) @@ -34,13 +35,15 @@ namespace HoistingCrane.Generics if (Count >= _maxCount) throw new StorageOverflowException(Count); _places.Insert(position, crane); + if(_places.Contains(null)) _places.Remove(null); return position; } /// Удаление объекта из набора с конкретной позиции public bool Remove(int position) { - if (_places[position] == null) + if (position < 0 || position > _maxCount || position >= Count || _places[position] == null) throw new CraneNotFoundException(position); + if ((position < 0) || (position > _maxCount)) return false; _places[position] = null; return true; @@ -56,7 +59,9 @@ namespace HoistingCrane.Generics { get { - if (position < 0 || position > _maxCount) + if (position < 0 || position > Count) + return null; + if (_places.Count <= position) return null; return _places[position]; } @@ -64,6 +69,8 @@ namespace HoistingCrane.Generics { if (position < 0 || position > _maxCount) return; + if (_places.Count <= position) + return; _places[position] = value; } }