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

  • Home
  • SEARCH
  • 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 8712465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:06:52+00:00 2026-06-13T05:06:52+00:00

What is the LINQ syntax for the Average need below. Both Select and SelectMany

  • 0

What is the LINQ syntax for the Average need below. Both Select and SelectMany fail me.
I can Max() and Sum() my internal list, but Average() wont compile.

The JSON version of the simple list looks like

[{"Week":6, "Matches":[{"Game":189},{"Game":149},{"Game":132}]} ....

var hiGame = games.Max(g => g.Matches.Max(m => m.Game)); // ok
var hiSeries = games.Max(g => g.Matches.Sum(m => m.Game)); // ok
var ave = games.Average(g => g.Matches.SelectMany(m => m.Game)); // no go

The type arguments for method ‘System.Linq.Enumerable.SelectMany(System.Collections.Generic.IEnumerable, System.Func>)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.

  • 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-13T05:06:53+00:00Added an answer on June 13, 2026 at 5:06 am

    I think you want your SelectMany on the outside:

    var ave = games.SelectMany(g => g.Matches) // Flatten to a sequence of matches
                   .Average(m => m.Game);      // Average by value of Game
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hoping someone can help me with the LINQ syntax to calculate an average. For
I love the Linq syntax and its power, but sometimes I just can't understand
How can I write in fluent linq syntax the case when sql statement? select
I need help with LINQ syntax or methodology, not sure which. Here's my issue:
How do I select multiple columns in linq to sql method syntax? I only
Linq in general, has extensions methods(at IEnumerable) like Where, Select, OrderBy. But use another
Just a little niggle about LINQ syntax. I'm flattening an IEnumerable<IEnumerable<T>> with SelectMany(x =>
I have a linq like syntax: MyListName . Where (Lots of stuff can() be
I know I can use linq syntax on collections that implement IQueryable or IEnumerable.
I am trying to convert this SQL to linq syntax, but I'm having some

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.