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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:27:23+00:00 2026-06-14T13:27:23+00:00

I haven’t done much LINQ before, so I often find some aspects confusing. Recently

  • 0

I haven’t done much LINQ before, so I often find some aspects confusing. Recently someone created a query that looks like the following using the GroupBy operator. Here’s what they did:

List<int> ranges = new List<int>() {100, 1000, 1000000};

List<int> sizes = new List<int>(new int[]{99,98,10,5,5454, 12432, 11, 12432, 992, 56, 222});

var xx = sizes.GroupBy (size => ranges.First(range => range >= size));

xx.Dump();

Basically I am very quite confused as to how the key expression works, i.e. ranges.First(range => range >= size

Can anyone shed some light? Can it be decomposed further to make this easier to understand? I thought that First would produce one result.

Thanks in advance.

  • 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-14T13:27:24+00:00Added an answer on June 14, 2026 at 1:27 pm

    size => ranges.First(range => range >= size) this Func builds key, on which sizes will be grouped. It takes current size and finds first range, which is greater or equal current size.


    How it works:

    For size 99 first range which >= 99 is 100. So, calculated key value will be 100. Size goes to group with key 100.

    Next sizes 98, 10, 5 also will get key 100 and go to that group.

    For size 5454 calculated key value will be 1000000 (it’s the first range which is greater that 5454. So, new key is created, and size goes to group with key 1000000.

    Etc.

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

Sidebar

Related Questions

I haven't used the STL much before, but I started to on this huffman
Haven't done as much of Javascript as I should have done. I am trying
haven't used regex replaces much and am not sure if how I have done
Haven't seen this before so hopefully someone has a easy solve, I have a
I haven't done a lot of work with multi-level, pure CSS drop-down menus before,
Haven't done ASP.NET development since VS 2003, so I'd like to save some time
haven't done much jquery and ran into a problem. I'd like to bind hover
I haven't been able to find any useful resources online on how to do
I haven't been able to find a tutorial on how to properly setup a
Haven't found a solution to this problem yet, have tried some things... I have

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.