C# 程序查找数字值序列的平均值
使用 Linq Aggregate()方法查找数字值序列的平均值
首先,设定一个序列
List<int> list = new List<int> { 5, 8, 13, 35, 67 };现在,使用可查询的平均值()方法获取平均值。
Queryable.Average(list.AsQueryable());
示例
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
static void Main() {
List<int> list = new List<int> { 5, 8, 13, 35, 67 };
double avg = Queryable.Average(list.AsQueryable());
Console.WriteLine("Average = "+avg);
}
}输出
Average = 25.6
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP