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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:41:20+00:00 2026-05-12T13:41:20+00:00

Phew where do I begin… OK, I have a list that I have to

  • 0

Phew where do I begin…
OK, I have a list that I have to ,,cut up” into smaller list depending on two properties. When I have finished working with the small list I want it’s items removed from the original list 🙂

f.ex. I have a List<> CustomerProducts, that contains two values CustomerID and ProductID. I begin by ordering the list:

var orderedList = CustomerProducts.OrderBy( c => c.CustomerID).ThenBy( c => c.ProductID)ToList( );

Assume the ordereded list now looks like this:

CustomerID = 1, ProductID = 61
CustomerID= 1, ProductID = 61
CustomerID= 1, ProductID = 87
CustomerID= 2, ProductID = 81
CustomerID= 2, ProductID = 53

Now I want a new list that contains only the first two items in the list (because they have the same CustomerID and ProductID), and remove these two items from the orderedList, and then continue doing the same to the rest … while the orderedList is not empty.

somehting like…

while(orderedList.Count > 0)
{
//create new list that has the same values…
//do some work on the new list
//remove the new list from the orderedList
//continue…
}

Any ideas of a smart solution for this?? smart meaning short code and pretty ofcourse 🙂

  • 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-12T13:41:21+00:00Added an answer on May 12, 2026 at 1:41 pm
    var groupedList = orderedList
      .GroupBy(c => new {c.CustomerId, c.ProductId})
      .OrderBy(g => g.Key.CustomerId)
      .ThenBy(g => g.Key.ProductId)
      .ToList();
    
    foreach(var group in groupedList)
    {
      List<CustomerProduct> cps = group.ToList();
      //do some work with this customer products
    
      //no need to do inefficient list removal - just move on to next group.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a master-slave MySQL binary log replication system (phew!) that, for some data,
I have a VB6 application that still references some old VB5 libraries (dll, vbr,
I have a website registration page, and I'm trying to compile a list of
I have a page (parent) that when a button (with .click funciton) is clicked
I'm working on a sketch search engine that correlates whatever someone's sketching with a
I am currently working on an advanced web application that contains a number of
phew! That was a long title. I'm reading WROX' book on Professional JavaScript for
I just wrote a perl script that is restarting a list of services on
PHEW. I'm serious. I'll spell it out as follows... The Storyboard has a Key
Hey there, I have a page with the jQuery Draggable() enabled on #person and

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.