4
IEnumerable<fishbiscuits> a = GetFishBiscuits(0);
IEnumerable<fishbiscuits> b = GetFishBiscuits(1);
if ([any of the results in either list match])
{
// Do something ie
Console.WriteLine("I see both a and b love at least one of the same type of fish biscuit!");
}
您可以使用linq查看两个IEnumerable数据是否包含任何常用条目?您可以使用linq查看两个IEnumerable数据是否包含任何常用条目?
太好了,我在摆弄'contains':) – NibblyPig 2011-03-07 16:56:05
了解Intersect()使用在所有对象上找到的Equals()方法;如果元素不是内置值类型,字符串或IEquatable/IStructuralEquatable实现,则运行时将使用Object中的默认引用相等性检查,这可能不是您想要的。 – KeithS 2011-03-07 17:15:59
@KeithS:是的,但你可以通过在对象本身上重写'Equals' /'GetHashCode'或者通过传递一个自定义的'IEqualityComparer'到'Intersect'方法来解决这个问题。 – LukeH 2011-03-07 17:21:28