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);
}
You can change your function to:
And then call it with: