Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Array.cs
1using System;
2using System.Collections;
3using System.Collections.Generic;
4
6{
11 public class Array<T> : IEnumerable<T>
12 {
13 private readonly T[] elements;
14
19 public static implicit operator T[](Array<T> A) => A.elements;
20
25 public static implicit operator Array(Array<T> A) => A.elements;
26
31 public static implicit operator Array<T>(T[] A) => new Array<T>(A);
32
37 public Array(int Length)
38 {
39 if (Length < 0)
40 throw new ArgumentException("Length must be non-negative.", nameof(Length));
41 }
42
47 public Array(T[] Elements)
48 {
49 this.elements = Elements;
50 }
51
59 public int Rank => 1;
60
72 public int Length => this.elements.Length;
73
77 public T[] Elements => this.elements;
78
84 public T this[int Index]
85 {
86 get => this.elements[Index];
87 set => this.elements[Index] = value;
88 }
89
96 public object Clone()
97 {
98 return new Array<T>((T[])this.elements.Clone());
99 }
100
135 public void CopyTo(Array<T> array, int index)
136 {
137 this.elements.CopyTo(array.elements, index);
138 }
139
146 IEnumerator IEnumerable.GetEnumerator()
147 {
148 return this.elements.GetEnumerator();
149 }
150
157 public IEnumerator<T> GetEnumerator()
158 {
159 return new ElementEnumerator(this.elements.GetEnumerator());
160 }
161
162 private class ElementEnumerator : IEnumerator<T>
163 {
164 private readonly IEnumerator e;
165
166 public ElementEnumerator(IEnumerator Enumerator)
167 {
168 this.e = Enumerator;
169 }
170
171 public T Current => (T)this.e.Current;
172
173 object IEnumerator.Current => this.e.Current;
174
175 public void Dispose()
176 {
177 }
178
179 public bool MoveNext()
180 {
181 return this.e.MoveNext();
182 }
183
184 public void Reset()
185 {
186 this.e.Reset();
187 }
188 }
189
203 public int GetLength(int dimension)
204 {
205 return this.elements.GetLength(dimension);
206 }
207
220 public int GetLowerBound(int dimension)
221 {
222 return this.elements.GetLowerBound(dimension);
223 }
224
238 public int GetUpperBound(int dimension)
239 {
240 return this.elements.GetUpperBound(dimension);
241 }
242
260 public object GetValue(int index)
261 {
262 return this.elements.GetValue(index);
263 }
264
287 public object GetValue(params int[] indices)
288 {
289 return this.elements.GetValue(indices);
290 }
291
296 public void Initialize()
297 {
298 this.elements.Initialize();
299 }
300
326 public void SetValue(object value, params int[] indices)
327 {
328 this.elements.SetValue(value, indices);
329 }
330
351 public void SetValue(object value, int index)
352 {
353 this.elements.SetValue(value, index);
354 }
355 }
356}
Generic array.
Definition: Array.cs:12
int GetLength(int dimension)
Gets a 32-bit integer that represents the number of elements in the specified dimension of the System...
Definition: Array.cs:203
int Rank
Gets the rank (number of dimensions) of the System.Array. For example, a one-dimensional array return...
Definition: Array.cs:59
void SetValue(object value, params int[] indices)
Sets a value to the element at the specified position in the multidimensional System....
Definition: Array.cs:326
int GetLowerBound(int dimension)
Gets the index of the first element of the specified dimension in the array.
Definition: Array.cs:220
Array(int Length)
Generic array.
Definition: Array.cs:37
IEnumerator< T > GetEnumerator()
Returns an System.Collections.IEnumerator for the System.Array.
Definition: Array.cs:157
int Length
Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Syste...
Definition: Array.cs:72
object GetValue(params int[] indices)
Gets the value at the specified position in the multidimensional System.Array. The indexes are specif...
Definition: Array.cs:287
int GetUpperBound(int dimension)
Gets the index of the last element of the specified dimension in the array.
Definition: Array.cs:238
void CopyTo(Array< T > array, int index)
Copies all the elements of the current one-dimensional array to the specified one-dimensional array s...
Definition: Array.cs:135
void SetValue(object value, int index)
Sets a value to the element at the specified position in the one-dimensional System....
Definition: Array.cs:351
void Initialize()
Initializes every element of the value-type System.Array by calling the default constructor of the va...
Definition: Array.cs:296
object GetValue(int index)
Gets the value at the specified position in the one-dimensional System.Array. The index is specified ...
Definition: Array.cs:260
object Clone()
Creates a shallow copy of the System.Array.
Definition: Array.cs:96
T[] Elements
Internal array of elements.
Definition: Array.cs:77
Array(T[] Elements)
Generic array.
Definition: Array.cs:47