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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:33:26+00:00 2026-06-02T06:33:26+00:00

I have a linq issue that I am trying to solve, I have some

  • 0

I have a linq issue that I am trying to solve, I have some users who can be part of multiple groups, now I am able to return which users belongs to a single group like so:

    List<Student> students = new List<Student>();
    public List<Student> ReturnStudentByGroupName(string groupName)
    {
        List<Student> student = (from g in students
                              where
                                  (from t in g.StudentGroup where t.GroupName == groupName select t).Count() > 0
                              select g).ToList();
        return student;
    }

My problem now tho is I need to find the common users of multiple groups? For instance who are the common members of group A and group B. Im not looking for a list of users of these two groups it should only return users if they belong to both groups.

Does anyone know how to do this using two strings as inputs i.e string firstgroupName, string secondgroupName. Then return common students?

  • 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-02T06:33:27+00:00Added an answer on June 2, 2026 at 6:33 am

    Well you said you only want to return a list of users that belong to Both groups A and B, so naturally you just need to modify a where statement with two conditions instead of one.

        List<Student> students = new List<Student>();
        public List<Student> GetIntersectingStudents(string groupOne, string groupTwo)
        {
            var student = from s in students
                          let grps = s.StudentGroup.ConvertAll(gn => gn.GroupName)
                          where grps.Contains(groupOne) && grps.Contains(groupTwo)
                          select s;
            return student.ToList();
        }
        public List<Student> GetIntersectingStudents(params string[] groups)
        {
            var student = from s in students
                          let grps = s.StudentGroup.ConvertAll(gn => gn.GroupName)
                          where !groups.Except(grps).Any()
                          select s;
            return student.ToList();
        }
    

    Here are a couple methods for you, one of which takes two arguments in the method (What you asked for) and another that takes a list of groups (if you need to get from three, instead of two, etc)

    EDIT:

    I thought i would throw this extra method in there as well, just for fun. It compiles a list of all the groups and their members.

        public static Dictionary<string, List<Student>> GetStudentGroups()
        {
            var temp = from s in students
                       let grps = s.StudentGroup.ConvertAll(gn => gn.GroupName)
                       from grp in grps
                       group s by grp
                       into g
                       select g;
            return temp.ToDictionary(grping => grping.Key, studnt => studnt.ToList());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some LINQ code that generates a list of strings, like this: var
I am trying to chain multiple compiled linq queries together. I have succeeded in
I have an issue while trying to parse an Xml to Objects using Linq
I have an odd linq subquery issue. Given the following data structure: Parents Children
I'm having an issue getting a LINQ query to work. I have this XML:
I have a Linq query that looks something like this: var myPosse = from
I have this linq query that works well (although it may be written better,
I have a Linq query that looks something like this: var query = from
I have two LINQ statements that I would like to make into one, but
I have a LINQ statement that returns an anonymous type. I need to get

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.