我正在尝试写入.xml文件。问题是,当我写作时,我收到错误消息:无法从'int'转换为'string'。现在我知道这意味着我需要将整数转换为字符串,但我对如何做到这一点很困惑。该 我正在使用的代码如下:
private void GetProperties()
{
//CreateNode(everything being referenced. Put text boxes, and drop down boxes here.
XmlTextWriter writer = new XmlTextWriter(@"C:\ForteSenderv2.0\Forte.dat", System.Text.Encoding.UTF8);
writer.WriteStartDocument(true);
//Making the code indeted by 2 characters.
writer.Formatting = Formatting.Indented;
writer.Indentation = 2;
//Making the start element "Table".
writer.WriteStartElement("Forte_Data_Gatherer_Application");
//Calling the rst of the .xml file to write.
CreateNode(Portbx.SelectedIndex, BaudRatebx.SelectedIndex, Databitsbx.SelectedIndex, Paritybx.SelectedIndex, StopBitsbx.SelectedIndex, Handshakingbx.SelectedIndex, writer);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
错误在CreateNode(Portbx.SelectedIndex, BaudRatebx.SelectedIndex, Databitsbx.SelectedIndex, Paritybx.SelectedIndex, StopBitsbx.SelectedIndex, Handshakingbx.SelectedIndex, writer);
答案 0 :(得分:2)
从整数到字符串没有隐式转换。您需要在索引参数上调用ToString()
:
CreateNode(Portbx.SelectedIndex.ToString(), ...
或者您需要更改CreateNode
的签名以获取整数
CreateNode(int Port, ...