简体   繁体   English

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

[英]How do you initialize and add data to variable of “[][]” in C#?

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? 如何初始化并向其添加数据?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM