企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
# 创建字典对象 主要由两部分构成 key和item,在括号中指明key 和 item 的类型。 `Dictionary <string, string> myDic = new Dictionary<string, string>();` 如果要创建的 item是 一个数组也行: `Dictionary<string, string[]> myDic = new Dictionary<string, string[]>;` ![](https://img.kancloud.cn/da/2c/da2cbe29febc109e4c1d3464cdb68a74_754x279.png) ``` Dictionary<string, string> myDic = new Dictionary<string, string>(); //key 和 item 都是 string 类型 for (int i = 0; i < dt1.Rows.Count; i++) //将dt 中的元素添加到字典中 { string k = "", value = ""; k = dt1.Rows[0][0].ToString(); value = dt1.Rows[0][0].ToString(); myDic.Add(k, value); } ``` # value是一个类 [https://blog.csdn.net/kasama1953/article/details/51698567](https://blog.csdn.net/kasama1953/article/details/51698567) # dictionary 转 dataTable [https://blog.csdn.net/l974199574/article/details/52181284](https://blog.csdn.net/l974199574/article/details/52181284)