65.9K
CodeProject is changing. Read more.
Home

Factorial Simplified using lambda

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.20/5 (7 votes)

May 2, 2011

CPOL
viewsIcon

18732

Factorial Simplified using lambda

Here is a trick which uses recursion in Lambda:
class Factorial
   {
       static void Main()
       {
           //Lambada Expression
           Func<int,int> call = null;
           call = x => x * (x == 1 ? 1 : call(x - 1));
           Console.WriteLine(call(5));
           Console.ReadLine();
       }
   }