Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading values from a DataTable column into a List<string> with LINQ

Tags:

linq

c#-4.0

I have a DataTable object with 5 columns returned to me by a service. I am only interested in one of the columns, the FuncName column and would like my utility method that calls the service to strip out the extra information and just return a List<string> object with an element for the value of this column for each row of the DataTable. This seems like a perfect application for link to read the values from the DataTable and then add them to my List<string> but I just can't seem to figure out how best to write that code. I would think the Any<> method would be of some value, but I am not sure where to start.

like image 779
Michael Kingsmill Avatar asked Mar 10 '26 13:03

Michael Kingsmill


1 Answers

table.AsEnumerable().Select(dr => dr.Field<string>("FuncName")).ToList()
like image 157
SLaks Avatar answered Mar 12 '26 02:03

SLaks