Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:40:16+00:00 2026-06-02T02:40:16+00:00

I have a class named HardwarePerformance contain these fields: time,cpuUsagePercent,memoryUsagePercent,diskUsage,diskRead,diskWrite,latency. I had fill a

  • 0

I have a class named HardwarePerformance contain these fields: time,cpuUsagePercent,memoryUsagePercent,diskUsage,diskRead,diskWrite,latency.
I had fill a List object to contain the not statistics data.
I need to calculating the average value for all these fields in a Linq command.
I don’t know how to get the average value with Linq. Follow is the code I wrote (It’s incorrect of course).

var _hardwarePerf = (from _stats in _statsList 
                    where _time>=DateTime.Parse("2012-04-04 00:00:00")
                        &&_time<=DateTime.Parse("2012-04-04 11:00:00") 
                    select new {
                           Latency = _stats.latency, 
                           CpuUsagePercent = _stats.cpuUsagePercent, 
                           MemoryUsagePercent = _stats.memoryUsagePercent, 
                           DiskUsage = _stats.diskUsage, DiskRead = _stats.diskRead, 
                           DiskWrite = _stats.diskWrite
                    }).Average(Latency => Latency.Latency);

The syntax of this code is correct. But I want to calculating all the average value at the same time, how do I write my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:40:17+00:00Added an answer on June 2, 2026 at 2:40 am

    You can use “Group By” then you can use an average projection to calculate.

    var query = from _stats in _statsList 
        group _stats by new {
                   Latency = _stats.latency, 
                   CpuUsagePercent = _stats.cpuUsagePercent, 
                   MemoryUsagePercent = _stats.memoryUsagePercent, 
                   DiskUsage = _stats.diskUsage, 
                   DiskRead = _stats.diskRead, 
                   DiskWrite = _stats.diskWrite
    
        } into myGroup
        select new {
            AverageVal = myGroup.Average(x => x.Value),
            CpuUsagePercent = myGroup.Key.CpuUsagePercent,
            ... // the rest of your projection
    };
    

    LINQ Average

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named A . What the difference between these two statements?
I have a class named OrganizerNote with fields: public long id; public DateTime CreationDate;
i have class named Group i tried to test configuration: var cfg = new
I have a class named baseClass. From this class I inherit a class names
I have a Class named Constants that contains all the constant variable in my
I have a class named Person and in this class is the property PersonName
I have a class named project with the following data members. class Project {
I have a class named toto which I send to a function that does
I have a class named SuperclassA , and an class named ClassA . ClassA
I have a class named CommonCode that is used for stocking all methods I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.