下面的代码不输出流。对我来说看起来正确但不起作用。
LineItem i1 = new LineItem() { Id = 1, PartNumber = "abc" };
LineItem i2 = new LineItem() { Id = 2, PartNumber = "def" };
LineItem i3 = new LineItem() { Id = 3, PartNumber = "ghi" };
LineItem i4 = new LineItem() { Id = 4, PartNumber = "jkl" };
List<LineItem> l1 = new List<LineItem>();
l1.Add(i1);
l1.Add(i2);
l1.Add(i3);
l1.Add(i4);
Customer c1 = new Customer() { Id = 1, Company = "MSFT", Name = "John", LineItems = l1 };
XmlSerializer mySerializer = new XmlSerializer(typeof(Customer));
TextWriter myWriter = new StreamWriter(@"XMLFile1.xml");
mySerializer.Serialize(myWriter, c1);
myWriter.Close();