Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DynamicArray<T>// : IList<T>
- {
- public T[] RawArray;
- public int Count
- {
- get;
- private set;
- }
- public int Capacity
- {
- get;
- private set;
- }
- public bool IsReadOnly => throw new NotImplementedException();
- public T this[int index]
- {
- get
- {
- return RawArray[index];
- }
- set
- {
- RawArray[index] = value;
- }
- }
- /*
- public ref T this[int index]
- {
- get
- {
- return ref RawArray[index];
- }
- }
- */
- public DynamicArray(int capacity = 4)
- {
- Capacity = capacity;
- RawArray = new T[Capacity];
- }
- public void Add(T element)
- {
- if(Count == Capacity)
- {
- Capacity *= 2;
- Array.Resize(ref RawArray, Capacity);
- }
- RawArray[Count] = element;
- Count++;
- }
- public bool Remove(T item)
- {
- int index = Array.IndexOf(RawArray, item, 0, Count);
- if(index >= 0)
- {
- Count--;
- Array.Copy(RawArray, index+1, RawArray, index, Count-index);
- return true;
- }
- return false;
- }
- public int IndexOf(T item)
- {
- throw new NotImplementedException();
- }
- public void Insert(int index, T item)
- {
- throw new NotImplementedException();
- }
- public void RemoveAt(int index)
- {
- throw new NotImplementedException();
- }
- public void Clear()
- {
- throw new NotImplementedException();
- }
- public bool Contains(T item)
- {
- throw new NotImplementedException();
- }
- public void CopyTo(T[] array, int arrayIndex)
- {
- throw new NotImplementedException();
- }
- public IEnumerator<T> GetEnumerator()
- {
- throw new NotImplementedException();
- }
- /* IEnumerator IEnumerable.GetEnumerator()
- {
- throw new NotImplementedException();
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement