title: Using Statements in DataTable
body: <p>In my below function...I want to return DataTable..</p>
  
  <p>Should I convert the below line</p>
  
  <p><code>DataTable table = CreateTable&lt;T&gt;();</code></p>
  
  <p>to following</p>
  
  <pre><code>using(DataTable table = CreateTable&lt;T&gt;())
  {
  }
  </code></pre>
  
  <h2>Function</h2>
  
  <pre><code>public static DataTable ConvertTo&lt;T&gt;(IList&lt;T&gt; list)
  {
      DataTable table = CreateTable&lt;T&gt;();
  
      int iColCount = table.Columns.Count;
      for (int j = 0; j &lt; iColCount; j++)
      {
          DataColumn myDC = table.Columns[j];
          myDC.DataType = System.Type.GetType("System.String");
      }
  
      Type entityType = typeof(T);
      PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType);
      foreach (T item in list)
      {
          DataRow row = table.NewRow();
          foreach (PropertyDescriptor prop in properties)
          {
              row[prop.Name] = prop.GetValue(item);
          } table.Rows.Add(row);
      }
      return table;
  }
  </code></pre>