title: Getting anonymous type when converting list to DataTable
body: <p>I have a list where I select column <code>TaskId</code>(Global variable) and <code>EmpGuid</code>(from list) like:</p>
  <pre><code> var parameterstest = assignNotificationTableType.Select(x =&gt; new { TaskId, x.EmpGuid }).ToList();
  </code></pre>
  <p>So if I debug I get something like this:</p>
  <p><a href="https://i.stack.imgur.com/ksIdo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ksIdo.png" alt="enter image description here" /></a></p>
  <p>Now I create method to convert it to DataTable like:</p>
  <pre><code>public static DataTable ToDataTable&lt;T&gt;(List&lt;T&gt; items)
          {
  
              DataTable dataTable = new DataTable(typeof(T).Name);
  
              //Get all the properties
  
              PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
              if (Props.Length &gt; 0)
              {
                  foreach (PropertyInfo prop in Props)
                  {
                      if (GetDefault(prop.PropertyType.FullName) != null)
                      {
                          //Setting column names as Property names
                          dataTable.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
                      }
                  }
              }
              else
              {
                  dataTable.Columns.Add(&quot;myColName&quot;);
              }
              foreach (T item in items)
              {
                  if (item != null)
                  {
                      DataRow dr = dataTable.NewRow();
                      if (Props.Length &gt; 0)
                      {
                          foreach (PropertyInfo prop in Props)
                          {
                              if (GetDefault(prop.PropertyType.FullName) != null)
                              {
                                  //inserting property values to datatable rows
                                  dr[prop.Name] = prop.GetValue(item, null) ?? GetDefault(prop.PropertyType.FullName);
                              }
                          }
                      }
                      else
                      {
                          //inserting property values to datatable rows
                          dr[0] = item;
                      }
  
                      dataTable.Rows.Add(dr);
                  }
              }
  
              //put a breakpoint here and check datatable
  
              return dataTable;
  
          }
  
          public static object GetDefault(string dataType)
          {
  
              if (dataType.Contains(&quot;System.String&quot;))
              {
                  return string.Empty;
              }
              if (dataType.Contains(&quot;System.Boolean&quot;))
              {
                  return false;
              }
              if (dataType.Contains(&quot;System.Decimal&quot;))
              {
                  return 0.0;
              }
              if (dataType.Contains(&quot;System.DateTime&quot;))
              {
                  return DateTime.MinValue;
              }
              if (dataType.Contains(&quot;System.Int64&quot;))
              {
                  return 0;
              }
              if (dataType.Contains(&quot;System.Guid&quot;))
              {
                  return null;
              }
              if (dataType.Contains(&quot;System.Int16&quot;))
              {
                  return 0;
              }
              if (dataType.Contains(&quot;Int32&quot;))
              {
                  return 0;
  
              }
              if (dataType.Contains(&quot;System.Object&quot;))
              {
                  return null;
              }
  
              return null;
          }
  </code></pre>
  <p>But when I try to use as:</p>
  <pre><code> var parameters = ToDataTable(assignNotificationTableType.Select(x =&gt; new { TaskId, x.EmpGuid }).ToList());
  </code></pre>
  <p>Variable returns <code>{&lt;&gt;f__AnonymousType42}</code> instead DataTable</p>
  <p><a href="https://i.stack.imgur.com/j1wuk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j1wuk.png" alt="enter image description here" /></a></p>
  <p>I don't know why it returns AnonymousType. Some one know what is the issue there?</p>
  <p><strong>UPDATE</strong></p>
  <p><a href="https://i.stack.imgur.com/S2UzZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S2UzZ.png" alt="enter image description here" /></a></p>
  <p>As you can see Anonymous type datatable count rows correctly but ItemArray is always zero instead my values</p>