【发布时间】:2012-10-06 06:25:32
【问题描述】:
有没有办法从 DataTable 的单个列中提取所有项目,而不是使用 For Each 循环?
例如,以下从 DataTable 的单个列中的每一行构建 KeyValuePair 列表
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);
}
有没有更好和/或更快的方法来做到这一点?
【问题讨论】: