码迷,mamicode.com
首页 > 其他好文 > 详细

DataTable转Dictionary

时间:2019-01-15 17:00:22      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:[1]   new   datarow   i++   dict   ble   datatable   ict   cti   

DataTable dt = new DataTable();
dt.Columns.Add("name");
dt.Columns.Add("no");
dt.Columns.Add("age");
dt.Columns.Add("sex");
dt.Rows.Add(new object[] { "小张", "0001", 5, "男" });
dt.Rows.Add(new object[] { "小王", "0002", 6, "男" });
dt.Rows.Add(new object[] { "小李", "0003", 7, "女" });
Dictionary<string, string> dic = dt.Rows.Cast<DataRow>().ToDictionary(x => x[0].ToString(), x => x[1].ToString());
Dictionary<string, string> dic2 = dt.Rows.Cast<DataRow>().ToDictionary(x => x["name"].ToString(), x => x["sex"].ToString());
int i = 0;
Dictionary<string, int> dic3 = dt.Rows.Cast<DataRow>().ToDictionary(x => x["name"].ToString(), x =>i++);

DataTable转Dictionary

标签:[1]   new   datarow   i++   dict   ble   datatable   ict   cti   

原文地址:https://www.cnblogs.com/niguang/p/10272452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!