我有一本字典,我想检索与列表结果匹配的结果。
以下是我迄今所做的工作
Dictionary<string, Dictionary<string, int>> SomeDictionary = new Dictionary<string, Dictionary<string, int>>();
List<int> MyList = new List<int>()
{
2,3,4,5
};
Dictionary<string, int> internalDictionary = new Dictionary<string, int>();
internalDictionary.Add("two", 2);
internalDictionary.Add("three", 3);
internalDictionary.Add("four", 4);
internalDictionary.Add("five", 5);
Dictionary<string, int> AnotherDictionary = new Dictionary<string, int>();
AnotherDictionary.Add("six", 6);
AnotherDictionary.Add("three", 3);
AnotherDictionary.Add("seven", 7);
SomeDictionary.Add("Dictionary1", internalDictionary);
SomeDictionary.Add("Dictionary2", AnotherDictionary);
var res = from l in MyList
select(from q in
(from p in
(from s in SomeDictionary
select s)
select p) where q.Value.Equals(l) select q);
返回的值为空。我错过了什么?
我需要匹配值与内部字典值匹配的KeyValuePair
。
发布于 2015-04-02 22:59:52
试试这个:
var res = from l in MyList
from q in SomeDictionary
from w in q.Value
where w.Value == l
select w;
我明白了:
发布于 2015-04-02 22:55:48
解释:
因此,在将整数转换为字符串之后,创建了具有字符串和整数值的内部连接查询。请参阅可能需要输出的屏幕
这个Linq片段可能会有帮助:
var allinone = (from l in MyList
join d in SomeDictionary.SelectMany(s => s.Value) on l equals d.Value
select d);
https://stackoverflow.com/questions/29427530
复制相似问题