To get Column Names from a datatable in C#

public DataTable GetColumnNames(  System.Data.DataTable table)
{
List<string> lstColumn = new List<string>();
if (table != null)
{

foreach (System.Data.DataColumn col in table.Columns)
{
lstColumn.Add(col.ColumnName);

}
 return lstColumn;

}

Advertisements