[英]How to get value from Dictionary<string,object>
我有一本字典,我想检索与列表匹配的结果
这是我到目前为止所做的
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
,其中值匹配内部字典值。
说明:
因此,在将整数转换为字符串后,使用字符串和整数值创建了内部联接查询。 请参阅可能需要输出的截屏视频
这个Linq片段可能会有所帮助:
var allinone = (from l in MyList
join d in SomeDictionary.SelectMany(s => s.Value) on l equals d.Value
select d);
尝试这个:
var res = from l in MyList
from q in SomeDictionary
from w in q.Value
where w.Value == l
select w;
我得到这个:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.