2using System.Collections;
3using System.Collections.Generic;
11 public class Array<T> : IEnumerable<T>
13 private readonly T[] elements;
19 public static implicit
operator T[](
Array<T> A) => A.elements;
40 throw new ArgumentException(
"Length must be non-negative.", nameof(
Length));
72 public int Length => this.elements.Length;
84 public T
this[
int Index]
86 get => this.elements[Index];
87 set => this.elements[Index] = value;
98 return new Array<T>((T[])this.elements.Clone());
137 this.elements.CopyTo(array.elements, index);
146 IEnumerator IEnumerable.GetEnumerator()
148 return this.elements.GetEnumerator();
159 return new ElementEnumerator(this.elements.GetEnumerator());
162 private class ElementEnumerator : IEnumerator<T>
164 private readonly IEnumerator e;
166 public ElementEnumerator(IEnumerator Enumerator)
171 public T Current => (T)this.e.Current;
173 object IEnumerator.Current =>
this.e.Current;
175 public void Dispose()
179 public bool MoveNext()
181 return this.e.MoveNext();
205 return this.elements.GetLength(dimension);
222 return this.elements.GetLowerBound(dimension);
240 return this.elements.GetUpperBound(dimension);
262 return this.elements.GetValue(index);
289 return this.elements.GetValue(indices);
298 this.elements.Initialize();
326 public void SetValue(
object value, params
int[] indices)
328 this.elements.SetValue(value, indices);
353 this.elements.SetValue(value, index);
int GetLength(int dimension)
Gets a 32-bit integer that represents the number of elements in the specified dimension of the System...
int Rank
Gets the rank (number of dimensions) of the System.Array. For example, a one-dimensional array return...
void SetValue(object value, params int[] indices)
Sets a value to the element at the specified position in the multidimensional System....
int GetLowerBound(int dimension)
Gets the index of the first element of the specified dimension in the array.
Array(int Length)
Generic array.
IEnumerator< T > GetEnumerator()
Returns an System.Collections.IEnumerator for the System.Array.
int Length
Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Syste...
object GetValue(params int[] indices)
Gets the value at the specified position in the multidimensional System.Array. The indexes are specif...
int GetUpperBound(int dimension)
Gets the index of the last element of the specified dimension in the array.
void CopyTo(Array< T > array, int index)
Copies all the elements of the current one-dimensional array to the specified one-dimensional array s...
void SetValue(object value, int index)
Sets a value to the element at the specified position in the one-dimensional System....
void Initialize()
Initializes every element of the value-type System.Array by calling the default constructor of the va...
object GetValue(int index)
Gets the value at the specified position in the one-dimensional System.Array. The index is specified ...
object Clone()
Creates a shallow copy of the System.Array.
T[] Elements
Internal array of elements.
Array(T[] Elements)
Generic array.