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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:57:14+00:00 2026-06-14T05:57:14+00:00

I am working on some reporting code and I have found myself repeating a

  • 0

I am working on some reporting code and I have found myself repeating a certain piece of code which contains a where and select cause over and over again? The only piece of information changing is the target field.

    private static void UpdateResultsListInstructions(List<ManagementInfo> managementInfo, KeyValuePair<int, int> item)
    {
        managementInfo
            .Where(m => m.YearMonthNo == item.Key)
            .Select(m => m.VolumeOfInstructionsReceivedInMonth = item.Value)
            .ToList();
    }

    private static void UpdateResultsListClaims(List<ManagementInfo> managementInfo, KeyValuePair<int, int> item)
    {
        managementInfo
            .Where(m => m.YearMonthNo == item.Key)
            .Select(m => m.VolumeOfClaimsCancelled = item.Value)
            .ToList();
    }

Is it possible to pass in the selector as an argument so I can reuse one method?

Along the lines of

UpdateCommonResultsList(managementInfo, item, (m => m.VolumeOfClaimsCancelled = item.Value))

I can probably rejig all the code so that this is not necessary but now that I’ve had the thought I’d like to see if its possible. Any help appreciated.

  • 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-14T05:57:15+00:00Added an answer on June 14, 2026 at 5:57 am

    Although I don’t like the use of Select to update a list – I misread the question because it’s not usual to do that! – you can do it as follows:

    private static void UpdateCommonResultsList(
        List<ManagementInfo> managementInfo,
        KeyValuePair<int, int> item,
        Action<ManagementInfo, int> action)
    {
        managementInfo
            .Where(m => m.YearMonthNo == item.Key)
            .Select(m => { action(m, item.Value); return item.Value; })
            .ToList();
    }
    

    Call as

    UpdateCommonResultsList(
        managementInfo,
        item,
        (m, i) => m.VolumeOfClaimsCancelled = i);
    

    Your code will be a lot more conventional if you do this as

    private static void UpdateCommonResultsList(
        List<ManagementInfo> managementInfo,
        KeyValuePair<int, int> item,
        Action<ManagementInfo, int> action)
    {
        foreach (ManagementInfo m in managementInfo
            .Where(m => m.YearMonthNo == item.Key))
        {
            action(m, item.Value);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that has been working since it's beginning, well over a
I have some working code with a crutch to add BOM marker to a
So far, I have some working code that goes into a list of servers
I'm trying to simulate some code that I have working with SQL but using
I'm working some code that inserts csv rows into an SQLite database using Python.
I've been re-working some code due to a memory leak. The code is part
Working on some code for a machine problem; we've just started working with pointers,
After working on some test code for open ID authentication, I had a break
Whilst working on some generally horrible Javascript code this morning, I came across the
My code mkdir(/some/absolute/path,0777); and mkdir(relative/path, 0777); is not working, safe mode is turned off,

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.