C# Linq Sum() 方法
使用LinqSum()方法求元素的总和。
这是我们的整数元素列表。
Listlist = new List { 99, 34, 77, 75, 87, 35, 88};
现在使用该Sum()方法求和。
list.AsQueryable().Sum();
以下是查找具有整数元素的列表的元素总和的示例。
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List list = new List { 99, 34, 77, 75, 87, 35, 88};
int res = list.AsQueryable().Sum();
Console.WriteLine("Sum = {0}", res);
}
} 输出结果Sum = 495
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短