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 7526653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:53:31+00:00 2026-05-30T03:53:31+00:00

I need to average 3 IEnumerable collection and create a new IEnumerable with the

  • 0

I need to average 3 IEnumerable collection and create a new IEnumerable with the result as follows:

var result1 = GetResult1()//Returns an enumerable collection having elements 1,2,3,4

var result2 = GetResult2()//Returns an enumerable collection having elements 3,4,2,6

var result3 = GetResult3()//returns an enumerable collection having elements 2,5,1,6

//I need to create a collection which has the averages of the above results as below:

var result4 = GetResult4()//Should return 2.00,3.67,2.33,5.33.
  • Each results will be having the same number of elements i.e result1, result2, result3 will be having the same number of elements (in this case 4, but actually it can range till 1500).

  • Each element in the result corresponds to the average value of the results i.e in result4 collection the first element will be an average of 1,3,2 which corresponds to the average of the first element in result1,result2,result3 respectively and hence forth.

  • The resultant collection should be having decimal places rounded to 2.

An obvious answer is to iterate through each element in the collections and create the elements in the resultant collection manually (i.e via a for loop), however I want to avoid it as the results will have close to 1500 elements in each collection and would like to do some sort of lazy evaluation using LINQ.

Please can you help me with some pointers?

Cheers,
-Mike

  • 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-05-30T03:53:32+00:00Added an answer on May 30, 2026 at 3:53 am

    If you’re using .NET 4, you can use Enumerable.Zip to good effect here:

    var averages = result1.Zip(result2, (x, y) => x + y)
                          .Zip(result3, (xy, z) => (xy + z) / 3.0d)
                          .ToList();
    

    This won’t do any rounding – that would normally be more appropriate for a formatting step. Note that the values can only end with 0, 0.33, or 0.67 anyway, as you’re only dividing by 3. Here I’ve used double but another option would be to use decimal – it depends on what the values really mean.

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

Sidebar

Related Questions

Let's suppose I need to perform some average-length (several days) refactoring. I create mybranch
I need to average some values in a row -wise fashion, rather than a
I have a small image from a database and the image's average color need
Need a running (moving, rolling) average algorithm to calculate the 5-minute average bits that
In my C# (3.5) application I need to get the average color values for
We have this set of data that we need to get the average of
I have the following array, I need to reorder it by average rating descending.
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either
For a posterization algorithmn I'm going to need to average the color values (

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.