Skip to content

Instantly share code, notes, and snippets.

@ajpinedam
Created October 16, 2021 20:31
Show Gist options
  • Save ajpinedam/a8c305009bec732d8989bf5df83a2e4b to your computer and use it in GitHub Desktop.
Save ajpinedam/a8c305009bec732d8989bf5df83a2e4b to your computer and use it in GitHub Desktop.
Testing Twitter Preview
public class PowersOf2
{
static void Main()
{
// Display powers of 2 up to the exponent of 8:
foreach (int i in Power(2, 8))
{
Console.Write("{0} ", i);
}
}
public static System.Collections.Generic.IEnumerable<int> Power(int number, int exponent)
{
int result = 1;
for (int i = 0; i < exponent; i++)
{
result = result * number;
yield return result;
}
}
// Output: 2 4 8 16 32 64 128 256
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment