Лабораторная работа №4
This commit is contained in:
parent
4b22945de3
commit
443199e870
@ -9,7 +9,7 @@ namespace ProjectAccordionBus.CollectionGenericObjects;
|
|||||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
private readonly List<T?> _collection;
|
private readonly List<T> _collection;
|
||||||
|
|
||||||
private int _maxCount;
|
private int _maxCount;
|
||||||
public int MaxCount => _maxCount;
|
public int MaxCount => _maxCount;
|
||||||
@ -32,15 +32,21 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj)
|
||||||
{
|
{
|
||||||
if (_collection == null || _collection.Count == _maxCount) return -1;
|
if (Count == _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
_collection.Add(obj);
|
_collection.Add(obj);
|
||||||
return _collection.Count - 1;
|
return _collection.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
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);
|
_collection.Insert(position, obj);
|
||||||
return position;
|
return position;
|
||||||
@ -54,4 +60,6 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
_collection[position] = null;
|
_collection[position] = null;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user