Created
June 11, 2017 07:55
-
-
Save miteshsureja/d66004de5029d9d590818baf565bf464 to your computer and use it in GitHub Desktop.
Iterator Pattern using IEnumerable example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace IteratorPattern | |
{ | |
public class MyCollection : IEnumerable | |
{ | |
List<int> myList = new List<int>() { 2, 5, 3, 6, 4, 9 }; | |
public IEnumerator GetEnumerator() | |
{ | |
foreach (var item in myList) | |
yield return item; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace IteratorPattern | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
MyCollection coll = new MyCollection(); | |
foreach(var item in coll) | |
Console.WriteLine(item.ToString()); | |
Console.ReadLine(); | |
} | |
} | |
} |
Author
miteshsureja
commented
Jun 11, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment