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

时间:2021-02-06 15:10:47
string[] arr = { "fsdfd", "fsdf", "34534534", "45fgd232423", "3342gddvdff" };
            var query1 = arr.Min(str => str.Length);
            Console.WriteLine(query1);//最短字符串长度
            var query2 = arr.Max(str => str.Length);
            Console.WriteLine(query2);//最长字符串长度
            var query3 = arr.Average(strs => strs.Length);
            Console.WriteLine(query3);//平均字符串长度
            var query4 = arr.Sum(strs => strs.Length);
            Console.WriteLine(query4);//字符串之和