当前位置 : 主页 > 编程语言 > c语言 >

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

来源:互联网 收集:自由互联 发布时间:2021-06-24
LINQ中Equals和=之间有什么区别? 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 B
LINQ中Equals和=之间有什么区别?

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,原因几乎相同.

网友评论