2022-11-21 21:01:25 +04:00

81 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Airbus
{
internal class SetAirplaneGeneric<T>
where T : class
{
private readonly List<T> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetAirplaneGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
}
public int Insert(T airplane)
{
return Insert(airplane, 0);
}
public int Insert(T airplane, int position)
{
if (position < 0 || position > _places.Count) return -1;
_places.Insert(position, airplane);
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Remove(int position)
{
if (0 > position && position >= Count)
return null;
T delobj = _places[position];
_places[position] = null;
return delobj;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T this[int position]
{
get
{
if (position <= Count || position >= 0)
{
return _places[position];
}
else return null;
}
set
{
Insert(value, position);
}
}
public IEnumerable<T> GetAirplanes()
{
foreach (var car in _places)
{
if (car != null)
{
yield return car;
}
else
{
yield break;
}
}
}
}
}