PIBD-13_Marinenkova_V.A._LabWork04_Base #4

Closed
marva wants to merge 3 commits from LabWork04 into LabWork03
2 changed files with 27 additions and 5 deletions
Showing only changes of commit 4b22945de3 - Show all commits

View File

@ -14,11 +14,16 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
private int _maxCount;
public int MaxCount => _maxCount;
public int Count => throw new NotImplementedException();
public int Count => _collection.Count;
public int SetMaxCount { set => throw new NotImplementedException(); }
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
public T? Get(int position)
public ListGenericObjects()
{
_collection = new();
}
public T Get(int position)
{
if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) return null;

View File

@ -20,7 +20,24 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public int Count => _collection.Length;
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
public int SetMaxCount
{
set
{
if (value > 0)
{
if (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T?[value];
}
}
}
}
/// <summary>
/// Конструктор
@ -96,7 +113,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
{
return null;
}
T temp = _collection[position];
T? temp = _collection[position];
_collection[position] = null;
return temp;
}