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; } }