티스토리 뷰
// C# : Iterator
using System;
using System.Collections;
using System.Collections.Generic;
namespace Iteration
{
class Program
{
static void Main(string[] args)
{
Count c1 = new Count();
foreach (var item in c1)
{
Console.WriteLine(item);
}
}
}
class Count : IEnumerable<string>
{
public IEnumerator<string> GetEnumerator()
{
yield return "one";
yield return "two";
yield return "three";
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
}
/* Output
one
two
three
*/
'Series' 카테고리의 다른 글
Iterator [C#] class DaysOfTheWeek : IEnumerable - yield return (0) | 2018.06.15 |
---|---|
Iterator [C#] class Count : IEnumerable<string> - GetEnumerator (0) | 2018.06.15 |
Iterator [C#] class Count : IEnumerable - GetEnumerator (0) | 2018.06.15 |
Iterator [C#] class Count : IEnumerable - foreach (0) | 2018.06.15 |
Iterator [C#] IEnumerable<int> GetEvenNumber() (0) | 2018.06.15 |