我是 Linq 菜鸟,也许有人可以指出我正确的方向。这是怎么回事?这些匿名类型似乎具有相同的签名。
'*** Get all of the new list items'
Dim dsNewFiles = From l1 In list1 _
Where Not (From l2 In list2 _
Select l2.id, l2.timestamp).Contains(New With {l1.id, l1.timestamp})
我希望有某种方法可以在上面的代码中突出显示,但我收到编译错误:
Value of type '<anonymous type> (line n)' cannot be converted to '<anonymous type> (line n)'.
在“.包含(新的 {l1.id, l1.timestamp})"
我认为它认为匿名类型在某种程度上是不同的,但两个列表中的 id 和时间戳列是相同的。它们的顺序也相同。两者之间还有什么不同?
[美国东部时间 2009 年 7 月 10 日 16:28 编辑]
我尝试了用户 Meta-Knight (New With {Key l1.id, l1.timestamp}) 的建议代码,它修复了编译错误。但是,当我使用 List1 和 List2 运行代码时,如下所示:
List1 List2
id timestamp id timestamp
-- ---------- -- ----------
01 2009-07-10 00:00:00 01 2009-07-10 00:00:00
结果是:
dsNewFiles
id timestamp
-- ----------
01 2009-07-10 00:00:00
它应该是一个空列表。