title: List of lists in vb.net
body: <p><br>
  I am trying to create lists, that are then inserted into another list.
  For some reason the latter list gets overwritten each time I try to add new list item to it.<br><br>
  For the code below, first I want to add items to <code>Temp</code> list and after certain conditions have been met, add the <code>Temp</code> list as an item to the <code>Comp</code> list. After that, the cycle repeats, new and different <code>Temp</code> list should be created and the added to the <code>Comp</code> list as next item. So each item in <code>Comp</code> list should be different.<br><br>
  But in the end I get a <code>Comp</code> list that is filled with <code>Temp</code> lists that are all identical to the last <code>Temp</code> list added.<br>
  What am I doing wrong?</p>
  
  <pre><code>Function UniqueValueList2(ByVal InputObject As List(Of Object)) As List(Of List(Of Object))
      Dim vc As Integer = InputObject.Count
      Dim i As Integer = 1
      Dim Temp As New List(Of Object)
      Dim Comp As New List(Of List(Of Object))
  
      Dim CurrentObj As String
      Dim PrevObj As String
  
      Temp.Add(InputObject(0))
  
      Do While i &lt; vc
          CurrentObj = InputObject(i).fieldName
          PrevObj = InputObject(i-1).fieldName
  
          If CurrentObj = PrevObj Then
              Temp.Add(InputObject(i))
          Else
              Comp.Add(Temp)
              Temp.Clear()
              Temp.Add(InputObject(i))
          End If
          i = i + 1
      Loop
      Comp.Add(Temp)
      UniqueValueList2 = Comp
  End Function
  </code></pre>