C# 表达式体方法 C#算阶乘

        //表达式体方法
        private int Add(int a, int b) => a + b;
        [Fact]
        public void Test()
        {
            
            var result1 = Factorial(1);//1
            var result2 = Factorial(2);//2
            var result3 = Factorial(3);//6
            var result4 = Factorial(4);//24
            var result5 = Factorial(5);//120
            var result6 = Add(100, 200);//300
            Console.WriteLine("result6:{0}", result6);
            var result7 = Math.Abs(123.456);
            var result8 = Math.Abs(-123.456);

            var reportId = string.Concat("VWFS_OnePage3.0_AFC", string.Format("{0:d8}", new Random().Next(10000000, 99999999)));

            var s = "123.456";
            var result9 = s.PadLeft(6);//123.456
            var result10 = s.PadLeft(6, '#');//123.456
            var result91 = s.Length == result9.Length;
            var result101 = s.Length == result10.Length;
            var result11 = s.Insert(4, "200#");//123.200#456
            s = "abcdefabcdef";
            var result12 = s[0];
            var result13 = s[s.Length - 1];
            var result14 = s.IndexOf("c");
            var result15 = s.LastIndexOf("c");
            var result16 = result14 == result15;
            var result17 = new int[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
            var result18 = new int[3][];
            result18[0] = new int[] { 1, 2, 3 };
            result18[1] = new int[] { 3, 4, 5 };
            result18[2] = new int[] { 7, 8, 9, 10 };
            //result18[3] = new int[] { 11, 12, 13, 14 };

            var result19 = DateTime.Now.Ticks;//638279743914331688

        }
        private int Factorial(int n)
        {
            if (n == 0)
                return 1;
            else
                return n * Factorial(n - 1);
        }

阶乘:

阶乘是基斯顿·卡曼(Christian Kramp,1760~1826)于 1808 年发明的运算符号,是数学术语。
一个正整数的阶乘(factorial)是所有小于及等于该数的正整数的积,并且0的阶乘为1。自然数n的阶乘写作n!。1808年,基斯顿·卡曼引进这个表示法。
亦即n!=1×2×3×...×(n-1)×n。阶乘亦可以递归方式定义:0!=1,n!=(n-1)!×n。

你可能感兴趣的:(c#,前端,javascript,开发语言,ecmascript)