title: How to convert List<dynamic> to List<OurClass> in c#
body: <p>I create a dynamic list at run-time and after execution I need to assign the list to my class properties</p>
  
  <pre><code>List&lt;tblchargemaster&gt; charge = new List&lt;tblchargemaster&gt;();
  
  charge = (List&lt;tblchargemaster&gt;) ObjDB.SelectQuery("tblchargemaster");
  </code></pre>
  
  <p><code>tblchargemaster</code> is the class type and <code>SelectQuery</code> function returns <code>List&lt;dynamic&gt;</code>. How can I convert this dynamic list to a list with my class type?</p>
  
  <pre><code>     public List&lt;dynamic&gt; SelectQuert(string TableName)
      {
          Conn.Open();
  
          DataTable dt = new DataTable("map");
  
          string Query = "Select * from " + TableName;            
          MySqlDataAdapter dr = new MySqlDataAdapter(Query, Conn);
          dr.Fill(dt);
  
          List&lt;dynamic&gt; dynamicDt = dt.ToDynamic();
  
          Conn.Close();
  
          return dynamicDt;
      }
  </code></pre>
  
  <p>And Generic Class is</p>
  
  <pre><code>    public static class DataTableExtensions
  {
      public static List&lt;dynamic&gt; ToDynamic(this DataTable dt)
      {
          var dynamicDt = new List&lt;dynamic&gt;();
          foreach (DataRow row in dt.Rows)
          {
              dynamic dyn = new ExpandoObject();
              foreach (DataColumn column in dt.Columns)
              {
                  var dic = (IDictionary&lt;string, object&gt;)dyn;
                  dic[column.ColumnName] = row[column];
                  dynamicDt.Add(dyn);
              }
          }
          return dynamicDt;
      }
  }
  </code></pre>