Reputation:
I ran into this answer which had a triple dot syntax in VB.NET that I have never seen before.
The query looks like this
Dim result =
From xcmp In azm...<Item>.<ItemPrice>.<Component>
Where xcmp.<Type>.Value = "Principal"
Select Convert.ToDecimal(xcmp.<Amount>.Value)
I tried to search on google about this triple dot syntax but I didn't get anything.
Can someone point to to some documentation about this syntax and I was also wondering it will work with C# or if there is an equivalent ?
Thanks
Upvotes: 5
Views: 1674
Reputation: 18345
The answer you're referring to was mine from another question, and the triple dot is just a shortcut for calling .Descendants()
. C# doesn't support inline XML, so you'll have to call the methods unless you're in VB. Here's the mapping:
...<node>
:= .Descendants("node")
.<node>
:= .Elements("node")
.@attr
:= .Attribute("attr").Value
You can see all of these from VB's intellisense.
Upvotes: 4
Reputation: 545913
The triple dots is a “descendant axis” which is used to access a list of XML nodes of a given name in XML literal syntax (“LINQ to XML”):
Gets all name elements of the [parent] element, regardless of how deep in the hierarchy they occur.
This syntax doesn’t exist in C#, only in VB (for the moment).
Upvotes: 6
Reputation: 2251
When using ... instead of ., you refer not to the direct child <Item>
, but to any <Item>
in the hierarchy tree.
So <A>...<B>
give a result for
<A>
<X1>
<X2>
<B></B>
</X2>
</X1>
</A>
whereas <A>.<B>
would give no result in this example...
Upvotes: 8