Add Iterator pattern

This commit is contained in:
Petrutiu Mihai
2016-06-22 19:37:05 +03:00
parent 1ab706016e
commit 35c3c5722d
19 changed files with 409 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
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;
}
}
}