Files
behavioral-patterns/src/IteratorPattern/TVExample/TVEnumerable/SamsungChannelIterator.cs
2016-07-14 12:21:16 +03:00

44 lines
1009 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace IteratorPattern.TVExample.TVEnumerable
{
public class SamsungChannelIterator : IEnumerator<Channel>
{
int currPos;
TVCableSupplier cableSupplier;
public SamsungChannelIterator(TVCableSupplier cableSupplier)
{
this.cableSupplier = cableSupplier;
currPos = -1;
}
public Channel Current { get { return cableSupplier.Channels[currPos]; } }
object IEnumerator.Current { get { return cableSupplier.Channels[currPos]; } }
public void Dispose()
{
}
public bool MoveNext()
{
if(currPos < cableSupplier.Channels.Count -1)
{
currPos++;
return true;
}
return false;
}
public void Reset()
{
currPos = -1;
}
}
}