gpt4 book ai didi

vb.net - LINQ 中的 Equals 和 = 有什么区别?

转载 作者:行者123 更新时间:2023-12-05 00:41:20 25 4
gpt4 key购买 nike

有什么区别等于 = 在LINQ?

Dim list As List(Of Foo) = (From a As Foo In FooList _
Join b As Bar In BarList _
On a.Something = b.Something _
Select a).ToList()

相对
Dim list As List(Of Foo) = (From a As Foo In FooList _
Join b As Bar In BarList _
On a.Something Equals b.Something _
Select a).ToList()

最佳答案

来自 The Moth谁引用了马特沃伦

"The reason C# has the word ‘equals’ instead of the ‘==’ operator was to make it clear that the ‘on’ clause needs you to supply two separate expressions that are compared for equality not a single predicate expression. The from-join pattern maps to the Enumerable.Join() standard query operator that specifies two separate delegates that are used to compute values that can then be compared. It needs them as separate delegates in order to build a lookup table with one and probe into the lookup table with the other. A full query processor like SQL is free to examine a single predicate expression and choose how it is going to process it. Yet, to make LINQ operate similar to SQL would require that the join condition be always specified as an expression tree, a significant overhead for the simple in-memory object case."



编辑

文章后面。

更新:来自 Visual Basic 团队的 Vladimir Sadov 告诉我,VB 也出于几乎相同的原因使用 Equals。

关于vb.net - LINQ 中的 Equals 和 = 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3018494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com