什么在VB.netLINQ到XML(C#至VB.net转换)
var list = (from x in xd.Descendants("product").Attributes("title") select
new { Title= x.Value}).ToList();
是等效的下面VB.net 昏暗列表=(从X在xd.Descendants( “产物”)。属性( “标题”)_ 选择新建(???))。ToList()
感谢
什么在VB.netLINQ到XML(C#至VB.net转换)
var list = (from x in xd.Descendants("product").Attributes("title") select
new { Title= x.Value}).ToList();
是等效的下面VB.net 昏暗列表=(从X在xd.Descendants( “产物”)。属性( “标题”)_ 选择新建(???))。ToList()
感谢
New With { .Title = x.Value }
你真的想要一个列表(中)?如果您的匿名类型只有一个属性,使用List(Of String)的结果是不是更容易?
下面是查询的完整vb.net语法以及一些用于测试的XML。我通常将.ToList呼叫分开,但主要是为了清晰起见。还要注意,使用下面的代码,直到.ToList调用才会执行查询,因此出于这个原因将它们分开也许会有帮助。
运行此代码之后,利斯塔是类型List(Of <anonymous type>)
和数组listB是类型List(Of String)
Dim testXml = <test>
<product title="Prod1"/>
<product title="Prod2"/>
<product title="Prod3"/>
</test>
Dim queryA = From t In testXml...<product> _
Select New With {.Title = [email protected]}
Dim listA = queryA.ToList
Dim queryB = From t In testXml...<product> _
Select [email protected]
Dim ListB = queryB.ToList