【发布时间】:2021-11-05 19:56:01
【问题描述】:
如何安全地返回与列表中的项目匹配的字典项目?
static void Test()
{
var dict = new Dictionary<string, string>();
dict.Add("license1", "123");
dict.Add("license2", "456");
dict.Add("license3", "789");
var list = new List<string>();
list.Add("444");
list.Add("111");
list.Add("123");
var result = dict.Values.Intersect(list);
//result should be only the matching item as a dictionary for dict -> for this example = "license1, 123"
}
【问题讨论】:
-
可惜字典是这样的
标签: c# list dictionary match equals