Is there a way to extract all items from a single column in a DataTable instead of using a For Each loop?
Eg, the following builds a List of KeyValuePair from each Row in a single column of a DataTable
List<KeyValuePair<string, double>> extract = new List<KeyValuePair<string, double>>();
foreach (DataRow item in _dataTableTest.Rows)
{
KeyValuePair<string, double> selection = (KeyValuePair<string, double>)item["Selection"];
extract.Add(selection);
}
Is there a better way and/or quicker way to do this?
You could use
Linq-To-DataTableNote that you need to add
using System.Linq;and that this is not “quicker” in terms of performance. It also uses loops internally.