Лабораторная работа №4

This commit is contained in:
mar-va 2024-04-03 17:32:55 +04:00
parent 4b22945de3
commit 443199e870

View File

@ -9,7 +9,7 @@ namespace ProjectAccordionBus.CollectionGenericObjects;
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
private readonly List<T?> _collection;
private readonly List<T> _collection;
private int _maxCount;
public int MaxCount => _maxCount;
@ -32,15 +32,21 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public int Insert(T obj)
{
if (_collection == null || _collection.Count == _maxCount) return -1;
if (Count == _maxCount)
{
return -1;
}
_collection.Add(obj);
return _collection.Count - 1;
return _collection.Count;
}
public int Insert(T obj, int position)
{
if (_collection == null || position < 0 || position > _maxCount) return -1;
if (Count == _maxCount || position < 0 || position > Count)
{
return -1;
}
_collection.Insert(position, obj);
return position;
@ -54,4 +60,6 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
_collection[position] = null;
return obj;
}
}