将值从DataTable列读取到List< string>与LINQ [英] Reading values from a DataTable column into a List<string> with LINQ
问题描述
我有一个 DataTable
对象,一个服务返回给我5列。我只对一个列, FuncName
列感兴趣,并希望我的实用程序方法调用服务,以剥离额外的信息,只返回一个 List< string>
对象,其中 DataTable
的每一行的值为该列的元素。这似乎是一个完美的应用程序链接读取的值从 DataTable
,然后将它们添加到我的列表< string>
但我只是不能找出如何最好地编写该代码。我认为 Any<>
方法将会有一些价值,但我不知道从哪里开始。
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.
推荐答案
table.AsEnumerable().Select(dr => dr.Field<string>("FuncName")).ToList()
这篇关于将值从DataTable列读取到List< string>与LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!