-2

我正在尝试写入 .xml 文件。问题是,当我写作时,我收到错误消息:Cannot convert from 'int' to '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);

4

1 回答 1

2

没有从整数到字符串的隐式转换。您需要调用ToString()索引参数:

CreateNode(Portbx.SelectedIndex.ToString(), ...

或者您需要更改的签名CreateNode以获取整数

CreateNode(int Port, ...

于 2013-07-26T14:38:42.763 回答