Something like this is actually better:
class MyExcelSheets
{
public List<string> MyColumnNames { get; set; }
public MyExcelSheets()
{
MyColumnNames = new List<string>();
}
}
MyExcelSheets mes = new MyExcelSheets();
foreach (DataColumn col in dTable.Columns)
{
myexcelSheet.MyColumnNames.Add(col.ColumnName.ToString());
}
This ensures type safety - you can add only strings into your MyColumnNames collection.
If you're having any issues, please let me know what line is it breaking at.
Arun