Recursion
In C#, a method can call itself. This process is called
recursion,
and a method that calls itself
is said to be
recursive.
In general, recursion is the process of defining something in terms of
itself and is somewhat similar to a circular definition. The key component of a recursive
method is that it contains a statement that executes a call to itself. Recursion is a powerful
control mechanism.
The classic example of recursion is the computation of the factorial of a number. The
factorial of a number
N
is the product of all the whole numbers between 1 and
N.
For
example, 3 factorial is 1×2×3, or 6. The following program shows a recursive way to
www.freepdf-books.com
Do'stlaringiz bilan baham: |