转换为Dictionary< string,IList< T>>使用LINQ [英] converting to Dictionary<string, IList<T>> using LINQ
本文介绍了转换为Dictionary< string,IList< T>>使用LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从字典中取出字典,如下所示:
I want to take a dictionary out of Dictionary as shown below:
Dictionary<string, SearchPanelViewModel> initialSearchData = GetSearchData();
var instructors = initialSearchData.Where(c => c.Key.Contains(searchKey))
.ToDictionary<string,IList<Instructor>>(k => k.Key.Remove(3, searchKey.Length),
v => v.Value.Instructors);
但是上面的行抛出错误.
But the above line is throwing error.
有什么办法可以使用LINQ吗?
Is there any way to do it using LINQ ?
任何帮助将不胜感激.
San
推荐答案
得到答案.....
Got the answer.....
实际上我做错了.代码应该是
Actually I was doing it wrong. Code should be
var instructors = initialSearchData.Where(c => c.Key.Contains(searchKey))
.ToDictionary(k => k.Key.Remove(3, searchKey.Length),
v => v.Value.Instructors);
它很好用.
这篇关于转换为Dictionary< string,IList< T>>使用LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文