Skip to content

Instantly share code, notes, and snippets.

@R2D221
Created March 23, 2015 16:24
Show Gist options
  • Save R2D221/d4d9110255fa0726369a to your computer and use it in GitHub Desktop.
Save R2D221/d4d9110255fa0726369a to your computer and use it in GitHub Desktop.
Demonstration of “inner functions” in C#
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