Recursion is exciting feature of a method. In C#, method can call itself, this is called recursion and such method is called by recursive method.
The following example shows how to find Factorial of any number with recursion:
private int GetFactorial(int num) { int result; if (num == 1) { return 1; } result = GetFactorial(num - 1) * num; return result; }
You can also find factorial without using recursion, see this example:
private int GetFectorial(int Number) { int functionReturnValue = 0; functionReturnValue = 1; for (int i = 1; i <= Number; i++) { functionReturnValue = functionReturnValue * i; } return functionReturnValue; }