使用 LINQ 省略字典值部分中的一些条目,并将其投影到维护原始键的新字典中
我有一个通用字典,其模板化方式如下:
Dictionary<object, IList<ISomeInterface>> dictionary1 = new Dictionary<object, IList<ISomeInterface>>();
如果我想针对任意键省略某些列表项(即组成字典的每个键值对的值部分中包含的列表中的项目) )给定一些任意条件(可以说省略列表项,其中列表项包含字符串“abc”)
我希望能够创建/项目到一个新字典中,该字典将包含包含列表的条目,而没有名称包含“abc”的项目“
如何使用 Lambda 表达式实现此目的?
我正在尝试这样的事情:
var result1 =dictionary1.Where(x => x.Value == x.Value.Select(y => !y.contains("abc"));
I have a generic dictonary which is templated in the following manner:
Dictionary<object, IList<ISomeInterface>> dictionary1 = new Dictionary<object, IList<ISomeInterface>>();
If I wanted to omit certain list items against arbitrary keys (that is the items that are in the list contained within the value part of each of the key value pairs making up the dictionary) given some arbitrary condition (lets say omitting list items where a list item contained the string "abc")
I would expect to able to create/project into a new dictionary which would contain entries which contained lists WITHOUT those items whose name contained "abc"
How do I achieve this using a Lambda expression?
I was trying something like this:
var result1 = dictionary1.Where(x => x.Value == x.Value.Select(y => !y.contains("abc"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想要它作为另一本词典吗?试试这个:
编辑:VB按照评论:
To you want it as another dictionary? Try this:
EDIT: VB as per the comment: