Created
March 23, 2015 16:24
-
-
Save R2D221/d4d9110255fa0726369a to your computer and use it in GitHub Desktop.
Demonstration of “inner functions” in C#
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
public static int Factorial(int number) | |
{ | |
if (number < 0) | |
throw new Exception("Sorry, number must be zero or positive"); | |
Func<int, int> innerFactorial = null; | |
innerFactorial = (_number) => | |
{ | |
if (_number <= 1) | |
return 1; | |
return _number * innerFactorial(_number - 1); | |
} | |
return innerFactorial(number); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment