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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:34:19+00:00 2026-06-13T23:34:19+00:00

I know I could do this with loops (as a matter of fact, I

  • 0

I know I could do this with loops (as a matter of fact, I currently am, but I am trying to learn / imporve my Linq skills and i also hope it will provide a more efficent solution. So, here’s my scenario:

Say I have the following 3 lists (I’m just making up a similar example, so forgive it’s stupidity):

Dim lstTeachers as New List(of string)
Dim lstStudentsSex as New List(of string)
Dim lstStudentName as New List(of string)

And they are, for example, as follows:

lstTeachers:     lstStudentsSex:     lstStudentName:
Teacher 1        Male                Whatever Name 1
Teacher 2        Female              Whatever Name 2 
Teacher 1        Female              Whatever Name 3
Teacher 1        Female              Whatever Name 4
Teacher 2        Male                Whatever Name 5
Teacher 3        Male                Whatever Name 6
Teacher 3        Female              Whatever Name 7
Teacher 1        Male                Whatever Name 8
Teacher 1        Female              Whatever Name 9
Teacher 2        Male                Whatever Name 10

Where each entry in each list matches the other entries with the same index – Basically like a datatable, just stored in separate lists.

Now, suppose I want to create the following structure with the following values:

Dim dictTeacherSexName as New Dictionary(Of String, Dictionary(Of String, List(of String)))

Dict1_Key:        Dict1_Value / Dict2_Key:         Dict2_Value:
Teacher 1         Male                             Whatever Name 1
                                                   Whatever Name 8
                  Female                           Whatever Name 3
                                                   Whatever Name 4
                                                   Whatever Name 9
Teacher 2 ...

… I hope this explains what I’m looking to accomplish.

Now, again, I know this may be a stupid idea, but I’m also asking it because I want to improve my Linq skills – especially Group By and multiple Selects which still catches me, so please help.

Thanks so much!

  • 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-13T23:34:20+00:00Added an answer on June 13, 2026 at 11:34 pm

    The three lists make things a bit difficult, but not impossible. Either you first zip the lists together as suggested by @fsimonazzi, or you base your query on the list indices rather than the list entries themselves. The result could look like this:

    (C#)

    var result = Enumerable
        .Range(0, lstTeachers.Count)
        .GroupBy(i => lstTeachers[i])
        .ToDictionary(g => g.Key, g => g
            .GroupBy(i => lstStudentsSex[i])
            .ToDictionary(h => h.Key, h => h
                .Select(i => lstStudentName[i])
                .ToList()));
    
    // result is Dictionary<string, Dictionary<string, List<string>>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this could be done manually with some hardcoded Linq Joins. However, I
I know I could solve this with a header but I'd rather not have
I don't know what could be causing this issue, but for some reason, elements
This could be a very basic Javascript I know but I just can't get
I know I could use PHP to do this, but wanted to find out
This is a great big mess... I know I could use an iframe, but
This could be a very simple question, but after a few hours trying to
Does anyone know where I could find this file on Ubuntu?
I know this doubt could be silly mistake. I am getting a variable from
Introduction: Now I know this question could be very broad and it would be

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.