using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
public class test : IEnumerable
{
public ArrayList tests = new ArrayList();
public test()
{
}
public IEnumerator GetEnumerator()
{
return new CustomEnum(tests);
}
}
public class CustomEnum : IEnumerator
{
private ArrayList _List;
private int _position = -1;
public CustomEnum(ArrayList list)
{
this._List = list;
}
public bool MoveNext()
{
return (++this._position < this._List.Count);
}
public void Reset()
{
this._position = -1;
}
public object Current
{
get
{
try
{
return this._List[this._position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}
static void Main(string[] args)
{
test tt = new test();
tt.tests.Add("one");
tt.tests.Add("two");
tt.tests.Add("three");
foreach (object Obj in tt)
Console.WriteLine((string)Obj);
Console.ReadLine();
}
}
}