这是我创建 XML 文件的代码
public void CreateXml(string[] names, string[] values, string type)
{
XElement xml = new XElement("Transaction",
new XElement("TransactionType", type));
foreach (var i in names)
{
foreach (var o in values)
{
xml.Add(new XElement(i.Replace(" ", string.Empty), o));
}
}
xml.Save("C:\\Users\\PHWS13\\Desktop\\sample.xml");
}
我的输出看起来像这样
<?xml version="1.0" encoding="UTF-8"?>
<Transaction>
<TransactionType>Void</TransactionType>
<Zip>1</Zip>
<Zip>2</Zip>
<PNRef>1</PNRef>
<PNRef>2</PNRef>
</Transaction>
但这是不对的,我期待更多这样
<?xml version="1.0" encoding="UTF-8"?>
<Transaction>
<TransactionType>Void</TransactionType>
<Zip>1</Zip>
<PNRef>2</PNRef>
</Transaction>
正如我注意到的值是正确的,但我只是重复,我该如何解决这个问题?
string[] textBoxNamesArray = flowLayoutPanelText.Controls.OfType<TextBox>()
.Select(r => r.Name)
.ToArray();
string[] textBoxTextsArray = flowLayoutPanelText.Controls.OfType<TextBox>()
.Select(r => r.Text)
.ToArray();