factorial of n numbers using c# lambda..?

后端 未结 4 946
名媛妹妹
名媛妹妹 2020-12-17 02:01

I just started playing with lambdas and Linq expression for self learning. I took the simple factorial problem for this. with the little complex scenario where find the fact

4条回答
  •  别那么骄傲
    2020-12-17 02:22

    Simple although no recursion here:

    public static int Factorial(this int count)
    {
            return count == 0
                       ? 1
                       : Enumerable.Range(1, count).Aggregate((i, j) => i*j);
    }
    
    3.Factorial() == 6
    

提交回复
热议问题