Linq的求最大值,最小值,平均值以及求和方法简介

时间:2021-10-06 15:11:54
int[] arr = { 34, 43, 45, 565, 2, 54, 456, 65, 2, 3, 6, 43, 65, 34 };

            var query1 = arr.Sum();
            Console.WriteLine("Sum:" + query1);
            var query2 = arr.Max();
            Console.WriteLine("Max:" + query2);
            var query3 = arr.Min();
            Console.WriteLine("Min:" + query3);
            var query4 = arr.Average();
            Console.WriteLine("Average:" + query4);