47
1
using System;
2
using System.Collections.Generic;
3
//
4
//Borrow from https://www.dotnetperls.com/yield
5
//
6
public class Program
7
{
8
public static IEnumerable<int> ComputePower(int number, int exponent)
9
{
10
//
11
//Return the result with yield out of a loop. Func/Method does not stop on 'return'. Yield return, returns control to continue below.
12
//
13
yield return 0;
14
15
int exponentNum = 0;
16
int numberResult = 1;
17
//
18
// Continue loop until the exponent count is reached.
19
//
20
while (exponentNum < exponent)
21
{
22
//
23
// Multiply the result.
24
//
Cached Result
2^0=0
2^1=2
2^2=4
2^3=8
2^4=16
2^5=32
2^6=64
2^7=128
2^8=256
2^9=512
2^10=1024
2^11=2048
2^12=4096
2^13=8192
2^14=16384
2^15=32768
2^16=65536
2^17=131072
2^1=2
2^2=4
2^3=8
2^4=16
2^5=32
2^6=64
2^7=128
2^8=256
2^9=512
2^10=1024
2^11=2048
2^12=4096
2^13=8192
2^14=16384
2^15=32768
2^16=65536
2^17=131072