Problem in converting a generic list<string> or string[] array to datatable
<p>I have the below function</p>

<pre><code>public static DataTable ToTable&lt;T&gt;(this IEnumerable&lt;T&gt; listItem)
{
            //Return null if the list is empty
            if (listItem == null || listItem.Count() == 0) return null;

            //Gets the type of the object
            var listType = listItem.First().GetType();

            //Initialize a new datatable
            var dataTable = new DataTable(listType.Name);
            //Create the datatable column names and types
            listType.GetProperties().ToList().ForEach(col =&gt; dataTable.Columns.Add(col.Name, col.PropertyType));

            //Get the datatable column names
            var dataTableColumnNames = dataTable.GetDatatableColumnNames();

            listItem.ToList().ForEach(item =&gt;
            {
                //create a new datarow
                var dataRow = dataTable.NewRow();

                dataTableColumnNames
                .Where(propName =&gt; listType.GetProperty(propName) != null)
                .ToList()
                .ForEach(columnName =&gt; 

//Exception happens here in the next line
     dataRow[columnName] = listType.GetProperty(columnName).GetValue(item, null));     
                //Add the row to the data table
                dataTable.Rows.Add(dataRow);
            });

            //Commit the changes to the datatable
            dataTable.AcceptChanges();
            return dataTable;
        }
</code></pre>

<p>It works great for dictionary object and generic list as <code>List&lt;MyClass&gt;</code> .. but not for 
<code>List&lt;string&gt;</code> or <code>string[]</code>.</p>

<p>For those I am getting an exception as <strong>Parameter count mismatch.</strong></p>

<p>The error is coming at </p>

<pre><code>dataRow[columnName] = listType.GetProperty(columnName).GetValue(item, null));
</code></pre>

<p>What is the mistake that is happening?</p>

<p>Please help</p>
