扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:论坛整理 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领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。