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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:41:48+00:00 2026-06-04T15:41:48+00:00

I found that when group by multiple values does not work well with VB.NET,

  • 0

I found that when group by multiple values does not work well with VB.NET, but it works well with C# ,here are my code, is there something wrong with my VB.NET Code?

Here is my VB.NET code:

Sub Main
  Dim empList As New List(Of Employee)()
    empList.Add(New Employee() With _
    {.ID = 1, .FName = "John", .Age = 23, .Sex = "M"c}) 
    empList.Add(New Employee() With _
    {.ID = 2, .FName = "Mary", .Age = 25, .Sex = "F"c})
    empList.Add(New Employee() With _
    {.ID = 3, .FName = "Amber", .Age = 23, .Sex = "M"c}) 
    empList.Add(New Employee() With _
    {.ID = 4, .FName = "Kathy", .Age = 25, .Sex = "F"c})
    empList.Add(New Employee() With _
    {.ID = 5, .FName = "Lena", .Age = 27, .Sex = "F"c}) 
    empList.Add(New Employee() With _
    {.ID = 6, .FName = "Bill", .Age = 28, .Sex = "M"c})
    empList.Add(New Employee() With _
    {.ID = 7, .FName = "Celina", .Age = 27, .Sex = "F"c}) 
    empList.Add(New Employee() With _
    {.ID = 8, .FName = "John", .Age = 28, .Sex = "M"c})

Dim query = empList.GroupBy(Function(x)  New With { .Age=x.Age, .Sex= x.Sex}) _
            .Select(Function(g) New With {g.Key, g.Count()}) 

For Each employee In query 
         Console.WriteLine(employee.Count)
Next employee 
End Sub


Public Class Employee 
    Private privateID As Integer
    Public Property ID() As Integer 

        Get 
            Return privateID
        End Get 

        Set(ByVal value As Integer) 
            privateID = value
        End Set 

    End Property 

    Private privateFName As String 
    Public Property FName() As String
        Get 
            Return privateFName
        End Get 

        Set(ByVal value As String) 
            privateFName = value
        End Set 
    End Property  

    Private privateAge As Integer 
    Public Property Age() As Integer
        Get 
            Return privateAge
        End Get 

        Set(ByVal value As Integer) 
            privateAge = value
        End Set 
    End Property  

    Private privateSex As Char 
    Public Property Sex() As Char
        Get 
            Return privateSex
        End Get 

        Set(ByVal value As Char) 
            privateSex = value
        End Set 
    End Property
End Class 

the out put for employee.Count are all 1 ,it is wrong.
I try it with C# ,it works well, the result is right.

//Here are my C# code:

void Main()
{
 var empList =new List<Employee>
 {
    new Employee {ID = 1, FName = "John", Age = 23, Sex = 'M'},
    new Employee {ID = 2, FName = "Mary", Age = 25, Sex = 'F'},
    new Employee {ID = 3, FName = "Amber", Age = 23, Sex = 'M'},
    new Employee {ID = 4, FName = "Kathy", Age = 25, Sex = 'F'},
    new Employee {ID = 5, FName = "Lena", Age = 27, Sex = 'F'},
    new Employee {ID = 6, FName = "Bill", Age = 28, Sex = 'M'},
    new Employee {ID = 7, FName = "Celina", Age = 27, Sex = 'F'},
    new Employee {ID = 8, FName = "John", Age = 28, Sex = 'M'} 
 };

var query = empList.GroupBy(x => new { x.Age,  x.Sex})
                   .Select(g=>new {g.Key, Count=g.Count()}); 

foreach (var employee in query )
   Console.WriteLine(employee.Count);

 }


public class Employee
{
  public int ID {get;set;}
  public string FName {get;set;}
  public int Age {get;set;}
  public char Sex {get;set;}
 }
  • 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-04T15:41:49+00:00Added an answer on June 4, 2026 at 3:41 pm

    This query should work:

    Dim query =
        From el In empList
        Group el By Key = new with {key el.Age, key el.Sex} 
            Into Group
        Select New  With {.key = Key,
                          .count = Group.Count()}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some code online that generally works, but I want to use it
I found that Maven implies specific directory layout. But I don't understand from here:
I found that this C++ code: vector<int> a; a.push_back(1); a.push_back(2); vector<int>::iterator it = a.begin();
I found that some result of MBRContains(g1,g2) and other functions seems not right to
I did some digging and I understand that the array means there are multiple
We currently have multiple .NET projects that we have developed using Visual Studio. Each
I found that using Smarty with PHP, sometimes extra time will need to be
I found that I have to perform a swap in python and I write
I found that I can set a tooltip on a QLineEdit as such: equation
I found that each thread still has its own registers. Also has its own

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.