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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:39:44+00:00 2026-06-17T13:39:44+00:00

I have this method: public Wrapper(Action<string> codeBlock) { //Code code code Parallel.ForEach<Computer>(Computers, computer =>

  • 0

I have this method:

public Wrapper(Action<string> codeBlock)
{
   //Code code code

        Parallel.ForEach<Computer>(Computers, computer =>
        {
                //CODE CODE 
               codeblock();

               //More code

        );
    //more code

 }

I use it to put a code block inside a wrapper that make important things to my app.

I invoke it using something like

Wrapper((s) => {

//My Code block
//code
//More code

});

I want to use the object computer of the collection Computers, created in the foreach of the wrapper, in my code block.
So if I made something like this:

Wrapper((s) => {

//My Code block
 AFunction(computer);
//More code

});

It obviouslly fails because “computer” does not exists in the contexts where I invoke the wrapper, only exists inside the foreach of the wrapper.

So how could I accomplish this? Maybe I have an error design?

  • 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-17T13:39:45+00:00Added an answer on June 17, 2026 at 1:39 pm

    Use

    public Wrapper(Action<Computer> codeBlock)
    {
        //...
        Parallel.ForEach<Computer>(Computers, computer =>
        {
               //...
               codeblock(computer);
               //...
        );
    }
    

    instead.

    Wrapper((s) => {    // s is of type Computer here now
        //...
        AFunction(s);
        //...
    });
    

    Of course , you may use Action<T1,T2> (i.e. relevant delegate with the necessary number of parameters) if you need both Computer and string within your code block. Lambda expression would be changed accordingly: (s, comp) => { /*...*/ }

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

Sidebar

Related Questions

In code-behind of an ASP.NET page I have this method: public string TestFunc() {
I have this method: public void testJSNI2(){ String x = test; } I can
I have this method call: public DataTemplate Create(Type type, string propertyName) { string str
I have this method in cs page: public String getToolTip(Object productId, Object imgBtnId) {
I have this method to display the contact numbers in my inbox: public ArrayList<String>
I have this method: public CampaignCreative GetCampaignCreativeById(int id) { using (var db = GetContext())
I have this recursive method: public Hund getMor(int id) { Hund barn = getHund(id);
Say I have this simple method: public IEnumerable<uint> GetNumbers() { uint n = 0;
I have this method to get a generic repository out of a dictionary: public
I have a thread with this run method: public void run(){ MAPTable t1 =

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.