转换为Dictionary< string,IList< T>>使用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);

它很好用.