İteras… enumerator ob… ne!??
Örnekle göstersek daha mantıklı olacak sanırım:
Örnekle göstersek daha mantıklı olacak sanırım:
Kod:
using System;
using System.Collections;
public class List
{
public static IEnumerable Power(int number, int exponent)
{
int counter = 0;
int result = 1;
while (counter++ < exponent)
{
result = result * number;
yield return result;
}
}
static void Main()
{
foreach (int i in Power(2, 8))
{
Console.Write("{0} ", i);
}
}
}
//Çıktı: 2 4 8 16 32 64 128 256