Created
February 15, 2021 07:39
-
-
Save DevWouter/1b708dd0d69db4393c83113e262eb531 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace HideAndSeek | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
foreach(var s in countDownTo(10)){ | |
Console.WriteLine(s); | |
} | |
} | |
static IEnumerable<string> countDownTo(int startAt, int stopAt=0) | |
{ | |
int counter = startAt; | |
while(true) | |
{ | |
switch(counter) | |
{ | |
case 2: | |
yield return "Ready!"; | |
break; | |
case 1: | |
yield return "Set!"; | |
break; | |
case 0: | |
yield return "Go!"; | |
break; | |
default: | |
yield return counter.ToString(); | |
break; | |
} | |
counter--; | |
if(counter < stopAt){ | |
yield break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment