filterediter.cs

来自「c#设计模式随书源码 c#设计模式随书源码」· CS 代码 · 共 42 行

CS
42
字号
using System;
using System.Collections ;
namespace FileredIterator
{
	/// <summary>
	/// Summary description for KidIterator.
	/// </summary>
	public class FilteredIterator : IEnumerator 	{
		private ArrayList kids;
		private int index;
		private string club;
		public FilteredIterator(ArrayList kidz, string club) 	{
			kids = kidz;
			index = 0;
			this.club = club;
		}
		//------
		public bool MoveNext() {
			bool more = index < kids.Count-1 ;
			if(more) {
				Kid kd = (Kid)kids[++index];
				more = index < kids.Count;
				while(more && ! kd.getClub().Equals (club)) {
					kd = (Kid)kids[index++];
					more = index < kids.Count ;
				}
			}
			return more;
		}
		//------
		public object Current {
			get {
				return kids[index];
			}
		}
		//------
		public void Reset() {
			index = 0;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?