I have a Linq query like this
var results= StudentsList.GroupBy(x=> x.GroupID)
.GroupBy(x=> x.Any(g=>g.IsQualified== true))
.Select(g=> g)
.ToList();
I want to store the part x.Any(g=>g.IsQualified== true)
into a variable so that I can change it on the fly (example: x.Any(g=>g.StudentName== "John")
) based on my requirement and without defining a new Linq query separately. Is that possible?
Pseudo Code
static void SomeFunction(Func<int, int> op)
{
var results= StudentsList.GroupBy(x=> x.GroupID)
.GroupBy(x=> op))
.Select(g=> g)
.ToList();
}
And call it:
SomeFunction(x => x.Any(g=>g.IsQualified== true));
SomeFunction(x => x.Any(g=>g.StudentName== "John"));
SomeFunction(x => x.Any(g=>g.Country== "USA"));