In my below function...I want to return DataTable..
Should I convert the below line
DataTable table = CreateTable<T>();
to following
using(DataTable table = CreateTable<T>())
{
}
Function
public static DataTable ConvertTo<T>(IList<T> list)
{
DataTable table = CreateTable<T>();
int iColCount = table.Columns.Count;
for (int j = 0; j < 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;
}