title: How to GroupBy a List(of object) in VB
body: <p>Before I asked this similar question for C# <a href="https://stackoverflow.com/questions/41097071/loop-through-a-list-and-combine-totals-where-an-identifier-is-the-same">here</a>. I am now trying to copy that into VB.</p>
  
  <p>I have a class for variations in my code like this: </p>
  
  <pre><code> Public Class TariffVariations
      Public Property TariffCode() As String
          Get
              Return m_TariffCode
          End Get
          Set(value As String)
              m_TariffCode = value
          End Set
      End Property
      Private m_TariffCode As String
  
      Public Property Eye() As String
          Get
              Return m_Eye
          End Get
          Set(value As String)
              m_Eye = value
          End Set
      End Property
      Private m_Eye As String
  
      Public Property Count() As Integer
          Get
              Return m_Count
          End Get
          Set(value As Integer)
              m_Count = value
          End Set
      End Property
      Private m_Count As Integer
  End Class
  </code></pre>
  
  <p>And I am looping through a repeater to build this List of Variations up. I have 8 objects in my list, 4 variations for each eye. 
  I am now trying to loop through that list and count the times that item is selected, hence the count.</p>
  
  <p>I have looked <a href="https://stackoverflow.com/questions/28090835/listof-t-groupby-visual-basic">here</a> and <a href="https://stackoverflow.com/questions/11121303/how-to-use-groupby-to-group-over-multiple-columns-with-vb-net">here</a> for examples of what to do with the Group by. I have also converted my code from C# from my previous question to VB. </p>
  
  <p>I have ended up with these two samples suited to my code. Please excuse the naming conventions:</p>
  
  <pre><code>    Dim lstNew = lstObjs.GroupBy(Function(c) c.TariffCode).Select(Function(c) New TariffVariations() With {.Eye = c.Key})
  
          Dim newCarList = lstObjs.GroupBy(Function(c) New With { _
   c.Eye, _
   c.TariffCode _
  }).[Select](Function(carGroup) New TariffVariations() With { _
    .Eye = carGroup.Key.Eye, _
    .TariffCode = carGroup.Key.TariffCode, _
    .Count = carGroup.Sum(Function(c) c.Count) _
  }).ToList()
  </code></pre>
  
  <p>Now in both those lists, instead of them collapsing to just 2 objects each for eyes Left and Right with the same code and count, instead keep the 8 from the list that is being grouped. </p>
  
  <p>How can I sort through these lists properly? What am I doing wrong here?</p>