1.向字典中写入键和值
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("personID", "2546");
dic.Add("telephone", "448");
dic.Add("name", "shali");
2.获取键和值的几种方式
List<string> nameKey2 = new List<string>(dic.Keys);
List<string> nameKey3 = dic.Keys.ToList();
string[] nameKey4 = dic.Keys.ToArray();
本文介绍了如何在C#中使用Dictionary进行键值对的添加,以及通过不同方式获取键和值,包括使用ToList和ToArray方法将Keys集合转换为列表和数组。这些基本操作对于理解和操作C#字典至关重要。

1353

被折叠的 条评论
为什么被折叠?



