http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx
public class PowersOf2
{
public static System.Collections.IEnumerable Power(int number, int exponent)
{
int counter = 0;
int result = 1;
while (counter++ < exponent)
{
result = result * number;
yield return result;
}
}
static void Main()
{
// Display powers of 2 up to the exponent 8:
foreach (int i in Power(2, 8))
{
Console.Write("{0} ", i);
}
}
}
/*
Output:
2 4 8 16 32 64 128 256
*/
'Programming' 카테고리의 다른 글
Avoiding the MSVCR100.dll, MSVCP100D.dll, or MSVCR100D.dll is missing error (0) | 2012.06.15 |
---|---|
웹에서 마우스 오른쪽 해제 (0) | 2012.06.15 |
C to Go (0) | 2012.06.15 |
(.NET) Free .NET decompiler - dotPeek (0) | 2012.06.14 |
Encoding Strings to Base64 in C# (0) | 2012.06.14 |