I have referred the below link in stack-overflow for my requirement which provide the matching key and Boolean results.I need the result of keys and values from the dictionary which matches with list of string.
Referred Link below: Array with Dictionary in c# using Linq
The example is provided in the same link above. Any how I will provide the same below
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};
What I tried is below:
var result = dict
.Select(x => new {
keys = x.Key,
values = values
.ToList()
.Any(x.Value.Contains)
});
I Expect the output be like {1,A},{2,D},{4,E} but actually coming {1,True},{4,True},{5,True}
Could some one help me on this.