【发布时间】:2014-11-12 01:12:40
【问题描述】:
我有一个WebItem 对象定义为
public class WebItem
{
public string Title;
public string Url;
public string RandomProperty1;
public string RandomProperty2;
public string RandomProperty3;
}
我有两个Lists 的WebItem 对象,我正在尝试找出List 1 中是否有List 2 中的对象。但问题是,如果至少 Title 和 Url 相同,我会认为它匹配。我不太关心其他属性的值是什么。
例子:
List 1
1: Title="Dog", Url="/dog.aspx", RandomProperty1="Yorkshire"
2: Title="Cat", Url="/cat.aspx", RandomProperty1="Persian", RandomProperty2="Grey"
3: Title="Rat", Url="/rat.aspx"
List 2
1: Title="Dog", Url="/dog.aspx", RandomProperty1="Pitbull"
2: Title="Cat", Url="/kitten.aspx", RandomProperty1="Persian", RandomProperty2="Grey"
3: Title="Bird", Url="/bird.aspx", RandomProperty1="Parrot"
在这种情况下,唯一的“匹配”将是“狗”,因为 Title 和 Url 相同。
我将如何在 Linq 中执行此操作?我考虑过使用.Intersect,但我不确定有关属性的条件。
【问题讨论】: