Mylist my = new Mylist();
for (int i = 0; i < 100; i++)
{
my.Add(i.ToString());
}
foreach (var item in my)
{
Console.WriteLine(item);
}
Console.ReadKey();
class Mylist:IEnumerable
{
int _size = 0;
int max = 0;
string[] li = new string[0];
public string this[int index]
{
get {
return li[index];
}
set {
li[index] = value;
}
}
public int Count
{
get {
return li.Length;
}
}
public void Add(string value)
{
if (_size == li.Length)
{
max = li.Length == 0 ? 4 : (li.Length * 2);
string[] tt = new string[_size];
li.CopyTo(tt, 0);
li = new string[max];
tt.CopyTo(li, 0);
}
li[_size++] = value;
}
public IEnumerator GetEnumerator()
{
return new GetEnumerator(li,_size);
}
}
class GetEnumerator : IEnumerator
{
string[] str;
int _index = -1;
int _size;
public GetEnumerator(string[] x,int size)
{
str = x;
_size = size;
}
public object Current
{
get { return str[_index]; }
}