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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:35:54+00:00 2026-06-12T05:35:54+00:00

I had a loop like this: this.results = new List<Tuple<int, IEnumerable<Thing>>>(); var utcNow =

  • 0

I had a loop like this:

        this.results = new List<Tuple<int, IEnumerable<Thing>>>();

        var utcNow = DateTime.UtcNow;
        var resultsLocker = new object();

        Parallel.ForEach(
            this.dataHelper.GetActiveIds(),
            id =>
            {
                var result = new Tuple<int, IEnumerable<Thing>>(
                    id,
                    this.dataHelper.GetThing(id, this.PossibleLastRunTime, utcNow));

                lock (resultsLocker)
                {
                    this.results.Add(result);
                }
            });

and, using this answer, translated to a more compact and understandable:

        this.results = this.dataHelper.GetActiveIds()
            .AsParallel()
            .Select(id => new Tuple<int, IEnumerable<Thing>>(
                id,
                this.dataHelper.GetThing(id, this.PossibleLastRunTime, utcNow)))
            .ToList();

Now I have a more complex nested loop as such:

        var measuresLocker = new object();
        var measures = new List<Tuple<int, object, object>>();

        Parallel.ForEach(
            this.results,
            result =>
            {
                foreach (var measuredValue in result.Item2.Select(destination =>
                    new Tuple<int, object, object>(
                        result.Item1,
                        destination.Message,
                        destination.DestinationName)))
                {
                    lock (measuresLocker)
                    {
                        measures.Add(measuredValue);
                    }
                }
            });

I want to do something similar, but I’m getting stuck with this code:

        measures = this.results
            .AsParallel()
            .Select(result => result.Item2.Select(destination =>
                new Tuple<int, object, object>(
                    result.Item1,
                    destination.Message,
                    destination.DestinationName)).ToList()).ToList();

I seem to be getting a list of lists and I simply want the one list as per my original code. Can this be done pretty succinctly using LINQ? And if so, how?

  • 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-12T05:35:55+00:00Added an answer on June 12, 2026 at 5:35 am

    To flatten a list of lists into a single list, use SelectMany() instead of Select().

       measures = this.results
            .AsParallel()
            .SelectMany(result => result.Item2.Select(destination =>
                new Tuple<int, object, object>(
                    result.Item1,
                    destination.Message,
                    destination.DestinationName)).ToList()).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using backbone.js, say I had a collection -- Albums var albums_collection = new Backbone.Collection([
If I had a string declared like this: message db ABCDEFGHIJ,0 how could I
I had a Java program that I run thousand times based on a loop
Had this working; at one stage. The problem is the following text is now
I once posted this question, but had no answer at all, this time, the
Riddle me this... in the while($row = mysql_fetch_assoc($result) and $runningOK) loop, if the PHP
still fairly new to matlab, picked up this data analysis code from someone and
Lets say i have this array of movie directors: var directors = ['Woody Allen',
I have been trying to figure this out for several hours but have had
Had to download Command Line Tools from Apple to get make to work, but

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.