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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:59:35+00:00 2026-06-08T04:59:35+00:00

I have two enumerables that I would like to use with PLINQ, how do

  • 0

I have two enumerables that I would like to use with PLINQ, how do I combine them correctly? Here they are:

List<Message> messageList=...;

IEnumerable<int> lineNums=Enumerable.Range(1,messages.Count);
IEnumerable<Message> messages=messageList;

In a nutshell, I want to apply some complex time consuming formatting in parallel and map the line numbers to the messages. Here is what I mean (without the line numbers), since I do not know how to integrate them into this expression:

var formattedLine=messageList.AsParallel().AsOrdered().Select(message =>
  {
    ... // Some work here to be done in parallel
    return string.Format(...); // Some formatting here of message
  }

I will then use the results of the formatting with a simple foreach:

foreach (var line in formattedLine)
  ...

Well the above is good for the messages, but I want to include some formatted lineNums in there from the enumerable in a one-to-one correspondance with the messages. I can’t just interlocked increment an integer in the lambda, because I will not get ordered results. So, basically I need a one-to-one mapping of the two enumerables as my params to the lambda, I suppose.

How do I do this?

  • 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-08T04:59:36+00:00Added an answer on June 8, 2026 at 4:59 am

    Use the select overload that takes an item and the item’s index, like this:

    var formattedLine=messageList.AsParallel().AsOrdered().Select((message, index) =>
    {
        ... // Some work here to be done in parallel
        return string.Format(...); // Some formatting here of message using index
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two enumerables: IEnumerable<A> list1 and IEnumerable<B> list2 . I would like to
Is it possible to use Except() for two List's that have two different classes
Assume that you have two IEnumerbale objects. How we can merge them (in some
I have two enumerables with the exact same reference elements, and wondering why Equals
I have two columns say Main and Sub . (they can be of same
I have some code that looks like the following. First I have some domain
I am trying to compare two arrays that always have different dimensions. eg. arr1
Have two issues one is showFromToolbar statement format warning issue and another is that
I have two objects @tracks (an enumerable) and @artist, and I'd like to create
I have two multisets, both IEnumerables, and I want to compare them. string[] names1

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.