Skip to content

Instantly share code, notes, and snippets.

@booyaa
Last active December 23, 2015 06:09
Show Gist options
  • Save booyaa/6592453 to your computer and use it in GitHub Desktop.
Save booyaa/6592453 to your computer and use it in GitHub Desktop.
DataTable to List using Linq

Assume that your data table looks like this

|field_name|other fields we don't care about|
|----------+--------------------------------|
|foo       |                                |
|bar       |                                |               
// might need to add a reference to System.Data.DataSetExtensions

using System.Collections.Generic;
using System.Linq;

// regular fixtures...

List<string> fields = (from row in ds.Tables["FIELDS"].AsEnumerable() select row.Field<string>("FIELD_NAME")).ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment