title: What is the fastest way to convert from DataTable to Generic List?
body: <p>I have a base class that has an API that returns a DataTable based on identifiers,
  And I need to have an object for each identifier.</p>
  
  <p>I hate to work with datatables, so I wanted to write a mapping code,
  that I only have to map the properties to the specific fields in the datatable.</p>
  
  <p>Is there any faster way to do it rather than my exmaple?</p>
  
  <p>Thanks.</p>
  
  <pre><code>public abstract class BaseClass&lt;T&gt; where T : BaseClass&lt;T&gt;
  {
      protected abstract T MapObject(DataRow row);
  
      protected abstract int SomeIdentifier { get; }
  
      public IList&lt;T&gt; GetData()
      {
          return ConvertDataTableToGenericList(GetDataTableFromOtherSource(this.SomeIdentifier));
      }
  
      private IList&lt;T&gt; ConvertDataTableToGenericList(DataTable table)
      {
          IList&lt;T&gt; objectList = new List&lt;T&gt;();
          foreach (DataRow row in table.Rows)
          {
              objectList.Add(MapObject(row));
          }
          return objectList;
      }
  }
  
  public class DerivedClass : BaseClass&lt;DerivedClass&gt;
  {
      public int ID { get; set; }
  
      protected override int SomeIdentifier
      {
          get { return 1; }
      }
  
      protected override DerivedClass MapObject(DataRow row)
      {
          return new DerivedClass()
          {
              ID = (int)row["ID"]
          };
      }
  }
  </code></pre>