插入List< string>和List< Object>进入字典 [英] inserting a List<string> and List<Object> into Dictionary

查看:90
本文介绍了插入List< string>和List< Object>进入字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目List<string> keysList<Objects> obj的列表,其中该对象有多个项目,而另一个对象又有多个项目,我们称其为"keyholder",其名称与键具有相同的值.

I have a list of items List<string> keys and List<Objects> obj where the object has multiple items where it has another object, lets call it keyholder which has the name where it is the same value with keys.

List <string> key = {"a","b"}

List <Object> obj = object with items {name, id, IEnumerable<keyholder>}

keyholder has value name which can be the same with key.

我想创建一个

key.ToDictionary(e=>e, f=> obj.Where(obj.keyholder.Where(keyholder.name == key));

仅当keyholder.name与键具有相同的值时,我才想将对象添加到字典中.

I want to add the object to the dictionary if and only if the keyholder.name has the same value with the key.

推荐答案

在你们的帮助下,由于IEnumerable可以位于项目列表中,因此我使用了contain关键字解决了该问题

With the help I got from you guys, I solved it by using a contain keyword since the IEnumerable can be in the list of items

key.ToDictionary(k => k, 
                 k => obj.Where(g => g.keyholder.Contains(k)).ToList());

这篇关于插入List&lt; string&gt;和List&lt; Object&gt;进入字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆