我使用xsd.exe从XML文件生成了一个新的C#类:
test.xml
--------
<?xml version="1.0" encoding="UTF-8"?>
<Output>
<ReportType name="New Reports">
<Reports>
<Report name="report1">
<Items>
<Item name="item1">
<Value>1.00</Value>
</Item>
<Item name="item2">
<Value>2.00</Value>
</Item>
</Items>
</Report>
<Report name="report2">
<Items>
<Item name="item3">
<Value>3.00</Value>
</Item>
<Item name="item4">
<Value>4.00</Value>
</Item>
</Items>
</Report>
</Reports>
</ReportType>
</Output>
You can see the C# class it generates here.
现在我正在尝试利用生成的类生成一个新的xml文件,我需要设置这个变量:
private OutputReportTypeReportsReport[][] reportsField;
如何初始化并向其添加数据?
答案 0 :(得分:2)
你可以这样做:
OutputReportTypeReportsReport[][] reportsField = new OutputReportTypeReportsReport[100][];
reportsField [0] = new OutputReportTypeReportsReport[1] { object1 };
reportsField [1] = new OutputReportTypeReportsReport[2] { object2, object3 };
...