主讲:李建忠
来源:
1: public interface IEnumerable
2: {
3: IEnumerator GetEnumerator();
4: }
5:
6: public interface IEnumerator
7: {
8: Object Current {get;}
9: bool Movenext();
10: void Reset();
11: }
12:
13: private class MyEnumerator: IEnumerator
14: {
15: int nIndex;
16: MyCollection collection;
17:
18: public MyEnumerator(MyCollection coll)
19: {
20: collection=coll;
21: nIndex=-1;
22: }
23:
24: public bool MoveNext()
25: {
26: nIndex++;
27: return (nIndex
28: }
29:
30: public int Current
31: {
32: get
33: {
34: return (collection.items[nIndex]);
35: }
36: }
37:
38: public void Reset()
39: {
40: nIndex=-1;
41: }
42: }