我得到一个错误,说不能隐式地将字符串类型转换为int。

时间:2022-02-04 16:34:26

I have an xml Nodelist with a child node named "Rating" the rating is of int type

我有一个名为“评级”的xml节点列表,它的评级是int类型的

progressBar1.Value = xList[0].ChildNodes[1].FirstChild.Value;

How do I use the ToString method here? I tried putting it at the end of the line but it still doesnt work

如何使用ToString方法?我试着把它放在线的末端,但还是不行

1 个解决方案

#1


4  

ProgressBar.Value property is int but XmlNode.Value returns string. And as error pointed, there is no implicit conversation from string to int.

ProgressBar。Value属性是int但XmlNode。返回字符串的值。正如错误指出的,从字符串到int不存在隐式对话。

If this XmlNode.Value value is a valid integer, you need to parse it to integer with Int32.Parse method like;

如果这XmlNode。值是一个有效的整数,您需要用Int32将其解析为整数。解析方法;

progressBar1.Value = Int32.Parse(xList[0].ChildNodes[1].FirstChild.Value);

#1


4  

ProgressBar.Value property is int but XmlNode.Value returns string. And as error pointed, there is no implicit conversation from string to int.

ProgressBar。Value属性是int但XmlNode。返回字符串的值。正如错误指出的,从字符串到int不存在隐式对话。

If this XmlNode.Value value is a valid integer, you need to parse it to integer with Int32.Parse method like;

如果这XmlNode。值是一个有效的整数,您需要用Int32将其解析为整数。解析方法;

progressBar1.Value = Int32.Parse(xList[0].ChildNodes[1].FirstChild.Value);