扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:论坛整理 2007年11月9日
关键字: Visual Basic C# LINQ 聚合
var totalVirtualMemory = (from p in Process.GetProcesses() select p.VirtualMemorySize64).Sum(); |
Dim totalVirtualMemory = Aggregate p In Process.GetProcesses _ Into p.VirtualMemorySize64 |
var totals = new { totalVirtualMemory = (from p in Process.GetProcesses() select p.VirtualMemorySize64).Sum(), totalWorkingSet = (from p in Process.GetProcesses() select p.WorkingSet64).Sum() }; |
var processes = (from p in Process.GetProcesses() select new { p.VirtualMemorySize64, p.WorkingSet64 } ).ToList(); var totals2 = new { totalVirtualMemory = (from p in processes select p.VirtualMemorySize64).Sum(), totalWorkingSet = (from p in processes select p.WorkingSet64).Sum() }; |
public static ProcessTotals Sum(this IEnumerable source) { var totals = new ProcessTotals(); foreach (var p in source){ totals.VirtualMemorySize64 += p.VirtualMemorySize64; totals.WorkingSet64 += p.WorkingSet64; } return totals; } public class ProcessTotals { public long VirtualMemorySize64 { get; set; } public long WorkingSet64 { get; set; } } var totals3 = (from p in Process.GetProcesses() select p).Sum(); |
Dim totals3 = Aggregate p In Process.GetProcesses _ Into virtualMemory = Sum(p.VirtualMemorySize64), _ workingSet = Sum(p.WorkingSet64) |
var processes = (from p in Process.GetProcesses() select new { p.VirtualMemorySize64, p.WorkingSet64 }); var totals4 = processes.Aggregate(new ProcessTotals(), (sum, p) => { sum.WorkingSet64 += p.WorkingSet64; sum.VirtualMemorySize64 += p.VirtualMemorySize64; return sum; }); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者