티스토리 뷰


// 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
*/


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함