C#中的LINQ相交/除非对象的一部分 [英] C# Linq intersect/except with one part of object
本文介绍了C#中的LINQ相交/除非对象的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经环顾四周,找不到任何帮助在这里。我有一个类:
I've had a look around and can't find anything to help out here. I've got a class:
class ThisClass
{
private string a {get; set;}
private string b {get; set;}
}
我想用相交和除LINQ的方法,即:
I would like to use the Intersect and Except methods of Linq, i.e.:
private List<ThisClass> foo = new List<ThisClass>();
private List<ThisClass> bar = new List<ThisClass>();
然后我填的是两个列表分开。我想要做的,比如(我知道这是不对的,只是伪代码),以下内容:
Then I fill the two lists seperately. I'd like to do, for example (and I know this isn't right, just pseudocode), the following:
foo[a].Intersect(bar[a]);
我将如何做到这一点?
How would I do this?
感谢您的帮助:)
推荐答案
也许
// returns list of intersecting property 'a' values
foo.Select(f => f.a).Intersect(bar.Select(b => b.a));
BTW财产 A
应该是公开的。
这篇关于C#中的LINQ相交/除非对象的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文