Click here to Skip to main content
13,457,717 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 30 Mar 2014

LINQ – Which Are the Aggregation Operators?

Rate this:
Please Sign up or sign in to vote.
Which are the Aggregation operators in LINQ


In the last blog post on LINQ, we have discussed about different Element Operators. You can read that article here. In this article, we will go over different Aggregation Operators in LINQ.

We know that every good querying language comes with Aggregation Operators and LINQ certainly provides some of them which are as follows:

  • Average – Calculates the average value in a sequence
  • Count/Long Count – Counts the elements in a sequence, overload accepts a predicate
  • Max - Returns the maximum value in a sequence
  • Min - Returns the minimum value in a sequence
  • Sum - Calculates the sum of values in a sequence

Let’s look at an example. Look at all software running on a machine using the Process class and we can produce a summary report about them.

Process[] runningProcesses = Process.GetProcesses();
var summary = new 
    ProcessCount = runningProcesses .Count(),
    WorkerProcessCount = runningProcesses.Count(
                         p => p.ProcessName ==  "w3wp"),
    TotalThreads = runningProcesses.Sum(p => p.Threads.Count),
    MinThreads = runningProcesses.Min(p => p.Threads.Count),
    MaxThreads = runningProcesses.Max(p => p.Threads.Count),
    AvgThreads = runningProcesses.Average(p => p.Threads.Count)

So the summary report includes ProcessCount which will give the count of running processes.

WorkerProcessCount is the count of those processes whose name=”w3wp”, that’s the worker processes for IIS where ASP.NET applications would run.

Then we will get the TotalThreads running on all the applications on the machine by summing up the Threads.Count property on runningProcesses.

Similarly, we can find the minimum number of threads, maximum number of threads and the average number of threads on a process.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Arun Ramachandran India
Software Developer
India India
Arun Ramachandran is a Software Engineer having hands on experience in different Microsoft Technologies who is presently working in Experion Technologies, India. He has written over 95 articles on the subject on his blog at Along with 3 years of hands on experience he holds a Master of Computer Applications degree from Cochin University of Science & Technology (CUSAT).

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180323.1 | Last Updated 31 Mar 2014
Article Copyright 2014 by Arun Ramachandran India
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid