小编And*_*eek的帖子

如何按键组合字典和列表

我有一个字典,看起来像这样:

Dictionary<String, String> dictionary = new Dictionary<string, string>{
  { "dog", "DOG" },
  { "cat", "CAT" },
  ...continued
};
Run Code Online (Sandbox Code Playgroud)

我想从具有匹配值的列表中提取Id值,如下所示:

List<Animal> records = new List<Animal>{
  { Id: "1", Name: "DOG" },
  { Id: "2", Name: "CAT" }
  ...continued
}
Run Code Online (Sandbox Code Playgroud)

我需要输出一个如下所示的字典:

Dictionary<String, String> newDictionary = new Dictionary<string, string>
  { "dog": "1" },
  { "cat": "2 }
  ...continued
}
Run Code Online (Sandbox Code Playgroud)

有一个简单的LINQ解决方案吗?

c# linq json dictionary list

0
推荐指数
1
解决办法
67
查看次数

标签 统计

c# ×1

dictionary ×1

json ×1

linq ×1

list ×1