title: C# determining the size of data in a DataTable
body: <p>I'm looking to get an estimate of the size of the data that is contained in DataTable in MB.
  I've to loop through each row and Marshal.SizeOf() but at runtime I get an error that </p>
  
  <blockquote>
    <p>Type 'System.String' cannot be marshaled as an unmanaged structure; no
    meaningful size or offset can be computed.</p>
  </blockquote>
  
  <p>here is a sample of the code I'm using to get the size:</p>
  
  <pre><code>private static int dsSize(DataSet ds)
      {
          int returnValue = 0;
  
          foreach (DataRow dr in ds.Tables[ds.Tables.Count - 1].Rows)
          {
              int rowSize = 0;
              for (int i = 0; i &lt; ds.Tables[ds.Tables.Count - 1].Columns.Count; i++)
              {
                  rowSize += System.Runtime.InteropServices.Marshal.SizeOf(dr[i]);
              }
              returnValue += rowSize;
          }
  
          return returnValue;
      }
  </code></pre>
  
  <p>any ideas as to how to achieve getting the size of data?</p>
  
  <p>thanks in advance</p>