title: DataTable to List<object>
body: <p>How do I take a DataTable and convert it to a List?</p>
  
  <p>I've included some code below in both C# and VB.NET, the issue with both of these is that we create a new object to return the data, which is very costly.  I need to return a reference to the object.</p>
  
  <p>The DataSetNoteProcsTableAdapters.up_GetNoteRow object does implement the INote interface.</p>
  
  <p>I am using ADO.NET, along with .NET 3.5</p>
  
  <p>c# code</p>
  
  <pre><code>public static IList&lt;INote&gt; GetNotes() 
  { 
      DataSetNoteProcsTableAdapters.up_GetNoteTableAdapter adapter =
          new DataSetNoteProcsTableAdapters.up_GetNoteTableAdapter(); 
      DataSetNoteProcs.up_GetNoteDataTable table =
          new DataSetNoteProcs.up_GetNoteDataTable(); 
  
      IList&lt;INote&gt; notes = new List&lt;INote&gt;(); 
  
      adapter.Connection = DataAccess.ConnectionSettings.Connection; 
      adapter.Fill(table); 
  
      foreach (DataSetNoteProcs.up_GetNoteRow t in table) { 
          notes.Add((INote)t); 
      } 
  
      return notes;
  } 
  </code></pre>
  
  <p>VB.NET Code</p>
  
  <pre><code>Public Shared Function GetNotes() As IList(Of INote)
      Dim adapter As New DataSetNoteProcsTableAdapters.up_GetNoteTableAdapter
      Dim table As New DataSetNoteProcs.up_GetNoteDataTable
  
      Dim notes As IList(Of INote) = New List(Of INote)
  
      adapter.Connection = DataAccess.ConnectionSettings.Connection
      adapter.Fill(table)
  
      For Each t As DataSetNoteProcs.up_GetNoteRow In table
          notes.Add(CType(t, INote))
      Next
  
      Return notes
  End Function
  </code></pre>