Need help in Assign the header of the DT to string[] in C#

Hi all ,
Can you help me with the expression to get the header of the DataTable and assign it to StringArray in c# code .
Eg:
image

I just want value from first column
image

I used
DT.Rows[1].ItemArray.Select(x => x.ToString()).ToArray(); which is giving the first row in the DT not the header .
Thanks,
Manchu.

Hi @Manchu

Try this:

string[] headers = DT.Columns.Cast<DataColumn>().Select(column => column.ColumnName).ToArray();

Thanks Parvathy , it worked.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.