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