开发者

How to convert VB statement into C#

开发者 https://www.devze.com 2022-12-21 19:21 出处:网络
I have dificulties to convert this vb code into C# D开发者_开发技巧im billingElem As XmlElement = _

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

精彩评论

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