Click here to Skip to main content
13,295,192 members (73,982 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

12.3K views
1 bookmarked
Posted 2 May 2011

Factorial Simplified using lambda

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

License

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

Share

About the Author

Steven.Pinto2000
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Social Group (No members)



You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralThis will generate a compiler warning, as you are referencin... Pin
Nelson LaQuet10-May-11 8:02
memberNelson LaQuet10-May-11 8:02 
GeneralNice Work. It is nothing but Creating Delegate Call and cal... Pin
rushijoshi5-May-11 1:39
memberrushijoshi5-May-11 1:39 
GeneralRe: ok thanks Pin
Steven.Pinto5-May-11 2:52
memberSteven.Pinto5-May-11 2:52 
Generalnice :) Pin
AmitMangal4-May-11 2:32
memberAmitMangal4-May-11 2:32 
GeneralRe: Thank you Pin
Steven.Pinto4-May-11 3:33
memberSteven.Pinto4-May-11 3:33 

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

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

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