Recursion
A method may call itself. It needs a base case.
Example
static long Fact(int n) => n <= 1 ? 1 : n * Fact(n - 1);
static int Fib(int n) => n < 2 ? n : Fib(n - 1) + Fib(n - 2);
Console.WriteLine(Fact(5));
Console.WriteLine(Fib(10));Exercise
Base case.
if (n <= ) return 1;
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.