开发者

How to convert VB statement into C#

I have dificulties to convert this vb code into C#

D开发者_开发技巧im billingElem As XmlElement = _
    CType(xmldoc.SelectSingleNode("/order/billing"), XmlElement)

converted as

XmlElement uinelement =
    (XmlElement)xmldoc.GetElementsByTagName("/Users/user/uin");

Error is Cannot implecitly convert XMLNodeList to XmlElement.

Thanks Kanta


Using VB.Net to C# Converter you get this:

XmlElement billingElem = (XmlElement)xmldoc.SelectSingleNode("/order/billing");


GetElementsByTagName can return more than one element, so it returns an XMLNodeList.

Change it to SelectSingleNode, which will only return one element and not a list.


I don't know why your converted code is calling a different method, but this will do what your original code does:

XmlElement billingElem = (XmlElement)xmldoc.SelectSingleNode("/order/billing");


Like this:

XmlElement billingElem = (XmlElement)xmldoc.SelectSingleNode("/order/billing");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜