Good afternoon, this task is given:
A file is given, the first three columns contain the last name, first name and patronymic, and the fourth is the email address. Write a program to convert the file to XML
my code is:
public class Person { public string Name { get; set; } public string SName { get; set; } public string OName { get; set; } public string Mail { get; set; } public Person() { } public Person(string name, string sname, string oname, string mail) { Name = name; SName = sname; OName = oname; Mail = mail; } } class Program { static void Main(string[] args) { string filename = @"C:\test\1.txt"; string line; Person person; person = new Person(); // Person[] people = new Person[] { person }; XmlSerializer formatter = new XmlSerializer(typeof(Person)); StreamReader sr = new StreamReader(@filename); while (!sr.EndOfStream) { line = sr.ReadLine(); string[] ss = line.Split(';'); Console.WriteLine(ss[0]); Console.WriteLine(ss[1]); Console.WriteLine(ss[2]); Console.WriteLine(ss[3]); Console.WriteLine("------------"); person.Name = ss[0]; person.SName = ss[1]; person.OName = ss[2]; person.Mail = ss[3]; using (FileStream fs = new FileStream(@"C:\test\people1.xml", FileMode.OpenOrCreate)) { formatter.Serialize(fs, person); } } sr.Close(); Since I read data from a file, it turns out that it serializes only the last line, how can I write all the lines?