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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:55:36+00:00 2026-05-30T11:55:36+00:00

How could I refactor this function so it could take any many to many

  • 0

How could I refactor this function so it could take any many to many parameters?

Program has many to many parameters as in Age, Color, etc…

So I have this function:

public int GetAgesOnProgram(IEnumerable<Program> ProgramList)
{
    return (from x in ProgramList
        where x.Ages.Any()
        select x.Ages).Count();
}

but I also need this one:

public int GetColorsOnProgram(IEnumerable<Program> ProgramList)
{
    return (from x in ProgramList
        where x.Colors.Any()
        select x.Colors).Count();
}

As I have up to 10 many to many relationships in Program, I guess it makes sense to have a single function that handles that?

EDIT:
How could I return the Age or Color List, rather than an int as in:

public IEnumerable<Color> GetColorsOnProgram(IEnumerable<Program> ProgramList)
{
    return (from x in ProgramList
        where x.Colors.Any()
        select x.Colors);
}
  • 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-05-30T11:55:37+00:00Added an answer on May 30, 2026 at 11:55 am

    You can change your function to:

    public int GetCountOnProgram(IEnumerable<Program> ProgramList, Func<Program,bool> whereClause)
    {
        return ProgramList.Where(whereClause).Count();
    }
    

    And then call it with:

    GetCountOnProgram(programList, x => x.Ages.Any());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How could I refactor this code to use only one Dir[ ] call? Dir[
Is there a pattern that I could apply to refactor this code? The only
Hi Guys could you please help me refactor this so that it is sensibly
I have this code: if (PsionTeklogix.Keyboard.Keyboard.GetModifierKeyState(Key.Orange) == KeyState.Lock) PsionTeklogix.Keyboard.Keyboard.InjectKeyboardCommand(Function.Orange, 0, 0); if (PsionTeklogix.Keyboard.Keyboard.GetModifierKeyState(Key.Blue) ==
I have this interesting jQuery function. It basically adds a click handler to link,
This is the code that I have to refactor for my homework: if (state
In a webservice I see this code: <WebMethod()> _ Public Function dosomething() As Boolean
This is my callback for my usort() public function sortProperties($a, $b) { $sortA =
Say I have code in my main mxml and in a function like this:
Could someone recommend any good resources for creating Graphics User Interfaces, preferably in C/C++?

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.