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, 5))
{
Console.Write("{0} ", i);
}
Console.ReadKey();
}
}
|
Imports System.Collections
Public Class List
Public Shared Function Power(number As Integer, exponent As Integer) As IEnumerable
Dim counter As Integer = 0
Dim result As Integer = 1
While System.Math.Max(System.Threading.Interlocked.Increment(counter),counter - 1) < exponent
result = result * number
yield Return result
End While
End Function
Private Shared Sub Main()
For Each i As Integer In Power(2, 5)
Console.Write("{0} ", i)
Next
Console.ReadKey()
End Sub
End Class
|