69619

Reading values from a DataTable column into a List with LINQ

Question:

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.

Answer1:

table.AsEnumerable().Select(dr => dr.Field<string>("FuncName")).ToList()

Recommend

  • How to negative match regex in JavaScript string replace? [duplicate]
  • Grails 3 - How to publish to Artifactory
  • Efficiently reading a csv file with windows newline on linux in Python
  • Android: How to correctly use NotifyDataSetChanged with SimpleExpandableListAdapter?
  • Primefaces :radioButton inside a ui:repeat
  • jQuery: add elements until a particular height is reached
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Breaking out column by groups in Pandas
  • Reduction and collapse clauses in OMP have some confusing points
  • Unable to get column index with table.getColumn method using custom table Model
  • Unity3D & Android: Difference between “UnityMain” and “main” threads?
  • Projection media query: browser support and workarounds?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Trying to switch camera back to front but getting exception
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Web-crawler for facebook in python
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • PHP: When would you need the self:: keyword?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • Turn off referential integrity in Derby? is it possible?
  • How to get Windows thread pool to call class member function?
  • apache spark aggregate function using min value
  • Add sale price programmatically to product variations
  • Django query for large number of relationships
  • Programmatically clearing map cache
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Observable and ngFor in Angular 2
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • How do I use LINQ to get all the Items that have a particular SubItem?