【发布时间】:2022-08-14 03:21:28
【问题描述】:
我基本上想知道如何用 C# 编写这个 (Extract all keys from a list of dictionaries)。
我有一个包含所有唯一键的字典列表。
我想将它们全部提取到字符串列表中(因为键是字符串)。
private List<Dictionary<string, string>> dictList = new List<Dictionary<string, string>>
{
new Dictionary<string, string>() { { \"a\", \"b\" } },
new Dictionary<string, string>() { { \"c\", \"d\" } },
};
private void GetDictListKeys()
{
List<string> keyList = new List<string>();
foreach(var dict in dictList)
{
keyList.Add(dict.Keys.ToString());
}
}
谢谢你。
标签: c# list dictionary