Serialize multiple objects

By Mash B

How to serialize multiple objects

FileStream Filewriter = new FileStream(@"D:\list.xml",FileMode.OpenOrCreate);
XmlSerializer
s = new XmlSerializer(typeof(Employees[])); // Make class as an array so that it will write multiple object.
Employees[] obj = null;
for (int i = 0; i < t.Rows.Count; i++)
{
Employees emp = new Employees();
emp.FirstName= t.Rows[i]["firstname"].ToString();
emp.LastName = t.Rows[i]["lastname"].ToString();
emp.BirthDate = Convert.ToDateTime(t.Rows[i]["birthdate"]);
emp.Extension = t.Rows[i]["extension"].ToString();
s.Serialize(w, emp);
obj[i] = emp;
}
s.Serialize(Filewriter, obj);

Serialize multiple objects  (814 Views)