“新……具有"是什么?语法在VB Linq中执行? [英] What does the "New ... With" syntax do in VB Linq?

查看:44
本文介绍了“新……具有"是什么?语法在VB Linq中执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此VB Linq查询的以下两个版本的结果之间有什么区别(如果有)?

What (if any) is the difference between the results of the following two versions of this VB Linq query?

'假设我们有一个XElement包含在其他地方定义的员工详细信息

' assume we have an XElement containing employee details defined somewhere else

Dim ee = From e In someXML.<Employee> _
Select New With {.Surname = e.<Surname>, .Forename = e.<Forename>}

Dim ee = From e In someXML.<Employee> _
Select Surname = .Surname = e.<Surname>, .Forename = e.<Forename>

即New ...语法的意义是什么?

ie what is the point of the New ... With syntax?

我怀疑这是一个简单的答案,但我找不到它-指向合适的教程或Microsoft文档的任何链接都将不胜感激.

I suspect that this has a simple answer, but I can't find it - any links to suitable tutorials or Microsoft documentation would be appreciated.

推荐答案

区别在于,第1个显式创建匿名类型.第二个是查询表达式,可以使用现有类型而不是创建匿名类型.从Cameron MacFarland链接的文档中:

The difference is that the 1st explicitly creates an anonymous type. The 2nd is a query expression, and may use an existing type rather than creating an anonymous type. From the documentation linked by Cameron MacFarland:

查询表达式并不总是需要创建匿名类型.如果可能,它们使用现有类型来保存列数据.当查询返回数据源中的整个记录​​或每个记录中的一个字段时,就会发生这种情况.

Query expressions do not always require the creation of anonymous types. When possible, they use an existing type to hold the column data. This occurs when the query returns either whole records from the data source, or only one field from each record.

这篇关于“新……具有"是什么?语法在VB Linq中执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆