自定义集合的一点问题 急!!!
using System;using System.Collections.Generic;
namespace CustomCollsion
{
class MyClass
{
public string Name;
public int Age;
public MyClass(string name, int age)
{
this.Name = name;
this.Age = age;
}
}
public class Itertator : IEnumerator, IEnumerable
{
private MyClass[] ClassArray;
int Cnt;
public Itertator()
{
ClassArray = new ClassArray[4];
ClassArray[0] = new ClassArray("K", 23);
ClassArray[1] = new ClassArray("g", 20);
ClassArray[2] = new ClassArray("x", 20);
ClassArray[3] = new ClassArray("w", 21);
Cnt = -1;
}
public void Reset()
{
Cnt = -1;
}
public bool MoveNext()
{
return (++Cnt < ClassArray.Length);
}
public object Current
{
get
{
return ClassArray[Cnt];
}
}
public IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}
static void Main()
{
Itertator It = new Itertator();
foreach (MyClass MY in It)
{
Console.WriteLine("Name:" + MY.Name.ToString());
Console.WriteLine("age:" + MY.Age.ToString());
}
}
}
}
错误 1 使用泛型 类型“System.Collections.Generic.IEnumerator<T>”需要“1”个类型参数 D:集合\集合\Program.cs 18 30 集合
麻烦帮忙分析分析 谢谢