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

This commit is contained in:
mar-va 2024-04-03 12:37:10 +04:00
parent fda3091411
commit 4b22945de3
2 changed files with 27 additions and 5 deletions

View File

@ -14,11 +14,16 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
private int _maxCount; private int _maxCount;
public int MaxCount => _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; 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 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> /// <summary>
/// Конструктор /// Конструктор
@ -96,7 +113,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
{ {
return null; return null;
} }
T temp = _collection[position]; T? temp = _collection[position];
_collection[position] = null; _collection[position] = null;
return temp; return temp;
} }