我的序列化代码是这样的..
public class slab
{
public int lowerlimit {get; set;}
public int upperlimit { get; set; }
public int percentage { get; set; }
}
public class Details
{
static void Main(string[] args)
{
slab s= new slab();
s.lowerlimit = 0;
s.upperlimit = 200000;
s.percentage = 0;
XmlSerializer serializer = new XmlSerializer(s.GetType());
StreamWriter writer = new StreamWriter(@"filepath");
serializer.Serialize(writer.BaseStream, s);
}
}
它工作正常,我得到的输出文件为:
<?xml version="1.0"?>
<slab xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<lowerlimit>0</lowerlimit>
<upperlimit>200000</upperlimit>
<percentage>0</percentage>
</slab>
但是我怎样才能序列化多个对象呢?我想得到一个输出文件
<slabs>
<slab>
<lowerlimit>0</lowerlimit>
<upperlimit>200000</upperlimit>
<percentage>0</percentage>
</slab>
<slab>
<lowerlimit>200000</lowerlimit>
<upperlimit>500000</upperlimit>
<percentage>10</percentage>
</slab>
<slab>
<lowerlimit>500000</lowerlimit>
<upperlimit>1000000</upperlimit>
<percentage>20</percentage>
</slab>
<slab>
<lowerlimit>1000000</lowerlimit>
<upperlimit>0</upperlimit>
<percentage>30</percentage>
</slab>
</slabs>