Youdakova D.R. PIbd-21 LabWork07 #7

Closed
Daniya_Youdakova wants to merge 6 commits from LabWork07 into LabWork06
2 changed files with 35 additions and 11 deletions
Showing only changes of commit 7a2b6d4d45 - Show all commits

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
@ -46,16 +47,16 @@ namespace AircraftCarrier
/// <returns></returns>
public int Insert(T AircraftCarrier, int position)
{
// проверка позиции
if (!CorrectPos(position))
// TODO проверка позиции
if (Count == _maxCount)
{
return -1;
throw new StorageOverflowException(_maxCount);
}
// вставка по позиции
if (position < 0 || position > _maxCount) return -1;
// TODO вставка по позиции
_places.Insert(position, AircraftCarrier);
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
@ -63,13 +64,14 @@ namespace AircraftCarrier
/// <returns></returns>
public T Remove(int position)
{
// проверка позиции
if (!CorrectPos(position))
return null;
// удаление объекта из массива, присовив элементу массива значение null
T temp = _places[position];
// TODO проверка позиции
if (position >= Count || position < 0)
{
throw new AircraftCarrierNotFoundException(position);
}
T aircraftcarrier = _places[position];
_places.RemoveAt(position);
return temp;
return aircraftcarrier;
}
/// <summary>
/// Получение объекта из набора по позиции

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace AircraftCarrier
{
[Serializable]
internal class StorageOverflowException : ApplicationException
{
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { }
public StorageOverflowException() : base() { }
public StorageOverflowException(string message) : base(message) { }
public StorageOverflowException(string message, Exception exception) :
base(message, exception)
{ }
protected StorageOverflowException(SerializationInfo info,
StreamingContext contex) : base(info, contex) { }
}
}