Click here to Skip to main content
Click here to Skip to main content

Factorial Simplified using lambda

By , 2 May 2011
Rate this:
Please Sign up or sign in to vote.
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));


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author


United States United States
No Biography provided
Group type: Social Group (No members)

Comments and Discussions

GeneralThis will generate a compiler warning, as you are referencin... PinmemberNelson LaQuet10-May-11 7:02 
GeneralNice Work. It is nothing but Creating Delegate Call and cal... Pinmemberrushijoshi5-May-11 0:39 
GeneralRe: ok thanks PinmemberSteven.Pinto5-May-11 1:52 
Generalnice :) PinmemberAmitMangal4-May-11 1:32 
GeneralRe: Thank you PinmemberSteven.Pinto4-May-11 2:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 2 May 2011
Article Copyright 2011 by Steven.Pinto2000
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid