BasicKnowledgeCSharp/LessonsAndTasks/Lesson 83 - Обобщения, generic типы, методы и классы/MyList.cs

22 lines
478 B
C#
Raw Permalink Normal View History

2024-10-05 09:59:53 +03:00
using System;
class MyList<T>
{
private T[] _array = Array.Empty<T>();
public T this[int index]
{
get => _array[index];
set => _array[index] = value;
}
public int Count => _array.Length;
public void Add(T value)
{
var newArray = new T[_array.Length + 1];
for (int el = 0; el < _array.Length; el++)
newArray[el] = _array[el];
newArray[_array.Length] = value;
_array = newArray;
}
}