using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WinFormsApp1 { internal class SetTraktorGeneric where T : class { private readonly List _places; public int Count => _places.Count; private readonly int _maxCount; private int TractorPlaces = 0; public SetTraktorGeneric(int count) { _maxCount = count; _places = new List(); ; } public int Insert(T tractor) { return Insert(tractor, 0); } public int Insert(T tractor, int position) { if (position < 0 && position > _maxCount) { return -1; } else { _places.Insert(position, tractor); return position; } } public T Remove(int position) { if (position < 0 || position >= _maxCount) { return null; } var result = _places[position]; _places.RemoveAt(position); return result; } public T this[int position] { get { if (position >= 0 && position < _maxCount && position < Count) { return _places[position]; } else { return null; } } set { Insert(value, position); } } public IEnumerable GetTraktor() { foreach (var traktor in _places) { if (traktor != null) { yield return traktor; } else { yield break; } } } } }