[原]把数组封装成集合

public class Intstrot : IEnumerator,IEnumerable
{
    int[] a;
    int CurrentIndex = -1;
    int EndIndex = -1;
    int containAblity;

    public Intstrot(int ContainAblity)
    {
        containAblity = ContainAblity;

        a = new int[containAblity];
    }

    public object Current
    {
        get {
              
                if (CurrentIndex > a.Length | CurrentIndex < 0)
                   throw new Exception();
                return a[CurrentIndex];
            }
    }

    public bool MoveNext()
    {
        return ++CurrentIndex < a.Length;
    }

    public void Reset()
    {
        CurrentIndex = -1;
    }

    public IEnumerator GetEnumerator()
    {
        return (IEnumerator)this;
    }

    public int Add(int value)
    {
        a[++EndIndex] = value;
        return EndIndex;
    }
}

 

posted @ 2007-02-26 15:02  馒头  阅读(322)  评论(0编辑  收藏  举报