You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
designPattern/DesignPattern/Iterator/CommonIterator.cs

35 lines
731 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Iterator
{
internal class CommonIterator : IIterator
{
private object[] collection;
private int index;
public CommonIterator(object[] collection)
{
this.collection = collection;
this.index = -1;
}
public bool HasNext { get { return index + 1 < collection.Length; } }
public object Next()
{
if (HasNext)
{
index++;
return collection[index];
}
else
{
return null;
}
}
}
}