分类: WINDOWS
2005-12-28 21:31:40
using System;
using System.Collections;
namespace myCon
{
class Student
{
public Student(){}
public Student(string strName)
{ name=strName; }
private string name;
public string Name
{
get{ return name; }
}
public string ToString()
{
return name;
}
}
class Connect: IEnumerable
{
IEnum ie = new IEnum();
public void Add(object obj)
{
ie.lst.Add(obj);
}
public void ReMove(object obj)
{
ie.lst.Remove(obj);
}
public IEnumerator GetEnumerator()
{
return ie;
}
class IEnum: IEnumerator
{
public int idx = -1;
public ArrayList lst = new ArrayList();
public void Reset()
{
idx = -1;
}
public object Current
{
get
{
if (idx>=0 && idx
return null;
}
}
public bool MoveNext()
{
idx++;
return idx
}
}
class Class1
{
static void Main(string[] args)
{
Connect con = new Connect();
con.Add(new Student("aaa"));
con.Add(new Student("bbb"));
con.Add(new Student("ccc"));
foreach(Student stu in con)
{
Console.WriteLine(stu.Name);
}
}
}
}