本文整理汇总了C#中System.Linq.Queryable.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# Queryable.Sum方法的具体用法?C# Queryable.Sum怎么用?C# Queryable.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Queryable.Sum方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1:
List<float> numbers = new List<float> { 43.68F, 1.25F, 583.7F, 6.5F };
float sum = numbers.AsQueryable().Sum();
Console.WriteLine("The sum of the numbers is {0}.", sum);
开发者ID:.NET开发者,项目名称:System.Linq,代码行数:5,代码来源:Queryable.Sum 输出:
The sum of the numbers is 635.13.
示例2:
float?[] points = { null, 0, 92.83F, null, 100.0F, 37.46F, 81.1F };
float? sum = points.AsQueryable().Sum();
Console.WriteLine("Total points earned: {0}", sum);
开发者ID:.NET开发者,项目名称:System.Linq,代码行数:5,代码来源:Queryable.Sum 输出:
Total points earned: 311.39
示例3: SumEx3
class Package
{
public string Company { get; set; }
public double Weight { get; set; }
}
public static void SumEx3()
{
List<Package> packages =
new List<Package>
{ new Package { Company = "Coho Vineyard", Weight = 25.2 },
new Package { Company = "Lucerne Publishing", Weight = 18.7 },
new Package { Company = "Wingtip Toys", Weight = 6.0 },
new Package { Company = "Adventure Works", Weight = 33.8 } };
// Calculate the sum of all package weights.
double totalWeight = packages.AsQueryable().Sum(pkg => pkg.Weight);
Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}
开发者ID:.NET开发者,项目名称:System.Linq,代码行数:20,代码来源:Queryable.Sum 输出:
The total weight of the packages is: 83.7
示例4: Queryable.Sum()
//引入命名空间
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Reflection;
public class MainClass{
public static void Main(){
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var query = numbers.Sum();
}
}
开发者ID:C#程序员,项目名称:System.Linq,代码行数:14,代码来源:Queryable.Sum
示例5: Queryable.Sum(projection)
//引入命名空间
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public static void Main() {
string[] words = { "cherry", "apple", "blueberry" };
double totalChars = words.Sum(w => w.Length);
Console.WriteLine("There are a total of {0} characters in these words.", totalChars);
}
}
开发者ID:C#程序员,项目名称:System.Linq,代码行数:15,代码来源:Queryable.Sum
注:本文中的System.Linq.Queryable.Sum方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论