title: How to use GroupBy() to group over multiple columns with VB.NET?
body: <p>i tried to do this like i would in C#, with an anonymous type but the result is just not correct.</p>
  
  <p>VB.NET example (wrong output):</p>
  
  <pre><code>Module Module1
  
  Sub Main()
      Dim ls As List(Of Employee) = New List(Of Employee)
      ls.Add(New Employee With {.Age = 20, .Sex = "M"})
      ls.Add(New Employee With {.Age = 20, .Sex = "M"})
      ls.Add(New Employee With {.Age = 20, .Sex = "M"})
      ls.Add(New Employee With {.Age = 30, .Sex = "F"})
      ls.Add(New Employee With {.Age = 30, .Sex = "F"})
  
      For Each item In ls.GroupBy(Function(k) New With {.Age = k.Age, .Sex = k.Sex})
          Console.WriteLine(String.Format("Group [Age: {0}, Sex: {1}] : {2} Item(s)", item.Key.Age, item.Key.Sex, item.Count()))
      Next
  
      Console.ReadLine()
  End Sub
  
  Class Employee
      Private _Age As Integer
      Public Property Age() As Integer
          Get
              Return _Age
          End Get
          Set(ByVal value As Integer)
              _Age = value
          End Set
      End Property
  
      Private _Sex As String
      Public Property Sex() As String
          Get
              Return _Sex
          End Get
          Set(ByVal value As String)
              _Sex = value
          End Set
      End Property
  End Class
  End Module
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Group [Age: 20, Sex: M] : 1 Item(s)
  Group [Age: 20, Sex: M] : 1 Item(s)
  Group [Age: 20, Sex: M] : 1 Item(s)
  Group [Age: 30, Sex: F] : 1 Item(s)
  Group [Age: 30, Sex: F] : 1 Item(s)
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>Group [Age: 20, Sex: M] : 3 Item(s)
  Group [Age: 30, Sex: F] : 2 Item(s)
  </code></pre>
  
  <p>C# example (correct output):</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          List&lt;Employee&gt; ls = new List&lt;Employee&gt;();
          ls.Add(new Employee { Age = 20, Sex = "M" });
          ls.Add(new Employee { Age = 20, Sex = "M" });
          ls.Add(new Employee { Age = 20, Sex = "M" });
          ls.Add(new Employee { Age = 30, Sex = "F" });
          ls.Add(new Employee { Age = 30, Sex = "F" });
  
          foreach (var item in ls.GroupBy(k =&gt; new { Age = k.Age, Sex = k.Sex }))
          {
              Console.WriteLine(String.Format("Group [Age: {0}, Sex: {1}] : {2} Item(s)", item.Key.Age, item.Key.Sex, item.Count()));
          }
          Console.ReadLine();
      }
  
      class Employee
      {
          public int Age { get; set; }
          public string Sex { get; set; }
      }
  }
  </code></pre>
  
  <p>does anybody see where my error is?</p>