Get Datatable Column Names extension methods for datatable

Niladri.Biswas
Posted by Niladri.Biswas under C# category on | Points: 40 | Views : 960
/// <summary>
/// Lists the column names in a datatable
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static List<string> GetDatatableColumnNames(this DataTable dt)
{
List<string> lstColumnNames = new List<string>();
Enumerable.Range(0, dt.Columns.Count)
.ToList()
.ForEach(i => lstColumnNames.Add(dt.Columns[i].ColumnName));
return lstColumnNames;
}

Comments or Responses

Login to post response