Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

LINQ – Which all are the Aggregation Operators?

, 31 Mar 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
CodeProject 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 provi

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 following:

  • 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 at all softwares 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.

Reference: Arun Ramachandran (http://BestTEchnologyBlog.Com)


License

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

Share

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 http://BestTEchnologyBlog.com. Along with 3 years of hands on experience he holds a Master of Computer Applications degree from Cochin University of Science & Technology (CUSAT).

Comments and Discussions

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