小编Nac*_*n R的帖子

我的问题是关于使用 C# linq 比较 List<string> 和 Dictionary <string, List<string>>

我已经根据我的要求在堆栈溢出中引用了以下链接,该链接提供匹配的键和布尔结果。我需要字典中与字符串列表匹配的键和值的结果。

参考下面的链接: Array with Dictionary in c# using Linq

该示例在上面的同一链接中提供。我将如何在下面提供相同的内容

Dictionary<int, List<string>> dict = new Dictionary<int, <string>>
{ 
    {1, new List<string>(){"A","B"}},
    {2, new List<string>(){"C","D"}},
    {3, new List<string>(){"G","H"}},
    {4, new List<string>(){"E","F"}},
    {5, new List<string>(){"I","J"}},
};

string[] values = new [] 
{
    "A", "D", "E"
};

var result = 
  from kvp in dict
  join s in values on kvp.Value equals s
select new {kvp.Key, Found = true};
Run Code Online (Sandbox Code Playgroud)

我试过的如下:

var result = dict
  .Select(x => new { 
     keys = x.Key, 
     values = values …
Run Code Online (Sandbox Code Playgroud)

c# linq dictionary list

3
推荐指数
1
解决办法
857
查看次数

标签 统计

c# ×1

dictionary ×1

linq ×1

list ×1