用.net和三元运算符解析XDocument
本文关键字:运算符 三元 XDocument net | 更新日期: 2023-09-27 18:01:48
在VB.NET
中,我使用以下命令来获取标记值:
Dim endval = cint(googleXMLdocument...<s:currentItemCount>.Value) - 1
在C#
中怎么做?
我尝试了以下操作,但是有语法错误
var endval = (short)googleXMLDoc...<s:currentItemCount>.Value) - 1;
C#
部分有什么问题?
下面是VB快捷方式的图例。净:http://msdn.microsoft.com/en-us/library/bb384974.aspx
c#没有相应的方法,所以你必须使用标准的LINQ to XML方法:
.<name> .Elements("name")
...<name> .Descendants("name")
.Value .First()
.@name .Attribute("name")
关于你的例子——你应该在c#中试试:
var endval = (short)googleXmlDoc.Descendants("currentItemCount").First() - 1;
但是,如果您向我们展示示例XML和预期的结果,则会容易得多。