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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:46:56+00:00 2026-06-05T01:46:56+00:00

I have about 20 functions with almost the same pattern, i run on array

  • 0

I have about 20 functions with almost the same pattern, i run on array of Sites, create SiteOperation with Site object and perform some operation ( in this case with one param but sometimes there are none or more)

int wantedBandwidthInLBps = 2048 / 8;
foreach (Sites site in _sitesManagement.GetAll())
{
 SiteOperation siteOperation = new SiteOperation(site);
 siteOperation.LimitBandwidth(wantedBandwidthInLBps);
}

foreach (Sites site in _sitesManagement.GetAll())
{
 SiteOperation siteOperation = new SiteOperation(site);
 siteOperation.KillJames();
}

foreach (Sites site in _sitesManagement.GetAll())
{
 SiteOperation siteOperation = new SiteOperation(site);
 siteOperation.FlyToMoon(2012, new TaskIdentifier(10,20));
}

Is it possible to wrap this code, so i will just send action to lets say _sitesManagement which will run this action on all Sites ?

  • 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-05T01:46:57+00:00Added an answer on June 5, 2026 at 1:46 am

    Try this:

    void PerformOperationOnAllSites(Action<SiteOperation> doIt) {
        foreach (Sites site in _sitesManagement.GetAll()) {
            SiteOperation siteOperation = new SiteOperation(site);
            doIt(siteOperation);
        }
    }
    
    ...
    
    _sitesManagement.PerformOperationOnAllSites(op => op.LimitBandwidth(wantedBandwidthInLBps));
    _sitesManagement.PerformOperationOnAllSites(op => op.KillJames());
    _sitesManagement.PerformOperationOnAllSites(op => op.FlyToMoon(2012, new TaskIdentifier(10,20));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some question about functions which have default parameters. import sys from random
I have seen slideUp and slideDown in jQuery. What about functions/ways for sliding to
Many people have argued about function size. They say that functions in general should
I have looked at the documentation on MSDN about these 2 functions. However, I
I have little doubt about string reading in C. string reading functions like gets,
I have been wandering about this for some time now. I'm still a beginner,
I have two websites that will share some resources, lets say, index.php, functions.js and
I have a simple function about neural network. This function gets a matrix, loads
I have been wondering about the reload() function in python, which seems like it
I have the following JQuery function about a range slider . It's just working

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.