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