-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDArray.cs
More file actions
49 lines (44 loc) · 1.12 KB
/
DArray.cs
File metadata and controls
49 lines (44 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//https://youtu.be/uXBnyYuwPe8
namespace D_A
{
internal class DArray<T> //: IEnumerable<T>
{
T[] array;
public int Length { get; set; }
public DArray(int size)
{
array = new T[size];
Length = size;
}
public T this[int idx]
{
get { return array[idx]; }
set {
try
{
array[idx] = value;
}catch (IndexOutOfRangeException)
{
var arraytmp = new T[++Length];
Array.Copy(array, arraytmp, array.Length);
arraytmp[idx] = value;
array = arraytmp;
}
}
}
//public IEnumerator<T> GetEnumerator()
//{
// return GetEnumerator();
//}
//IEnumerator IEnumerable.GetEnumerator()
//{
// throw new NotImplementedException();
//}
}
}