如何在C#中初始化并向“[] []”变量添加数据?

时间:2020-12-26 20:34:55

I generated a new C# class from a XML file using xsd.exe:

我使用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.

你可以在这里看到它生成的C#类。

Now I am trying to leverage the generated class to produce a new xml file and I need to set this variable:

现在我试图利用生成的类来生成一个新的xml文件,我需要设置这个变量:

private OutputReportTypeReportsReport[][] reportsField;

How do I initialize and add data to it?

如何初始化并向其添加数据?

1 个解决方案

#1


2  

You can do this:

你可以这样做:

OutputReportTypeReportsReport[][] reportsField = new OutputReportTypeReportsReport[100][];
reportsField [0] = new OutputReportTypeReportsReport[1] { object1 };
reportsField [1] = new OutputReportTypeReportsReport[2] { object2, object3 };
...

More info: http://msdn.microsoft.com/en-us/library/2s05feca.aspx

更多信息:http://msdn.microsoft.com/en-us/library/2s05feca.aspx

#1


2  

You can do this:

你可以这样做:

OutputReportTypeReportsReport[][] reportsField = new OutputReportTypeReportsReport[100][];
reportsField [0] = new OutputReportTypeReportsReport[1] { object1 };
reportsField [1] = new OutputReportTypeReportsReport[2] { object2, object3 };
...

More info: http://msdn.microsoft.com/en-us/library/2s05feca.aspx

更多信息:http://msdn.microsoft.com/en-us/library/2s05feca.aspx