2

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.

Michael Kingsmill
  • 1,815
  • 3
  • 22
  • 31
  • Out of curiosity, _why_ do you think `Any<>()` is relevant? – SLaks Mar 12 '12 at 18:01
  • Likely just ignorance on my part. I felt like because I wanted all rows in the list, that `Any<>()` filtered by an always true criteria would get me to the solution I was after. I see now that `Select()` is a much better fit for my situation. – Michael Kingsmill Mar 12 '12 at 19:17
  • Correct. `Any<>()` checks whether _any_ of the elements match a condition. It returns a boolean. The documentation is your friend. – SLaks Mar 12 '12 at 19:24

1 Answers1

13
table.AsEnumerable().Select(dr => dr.Field<string>("FuncName")).ToList()
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964