PIBD-13_Marinenkova_V.A._LabWork04_Base #4
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user