using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;
public static void Main()
Library lib = new Library(myBooks: new MyBooks(
booklist: new List<Book>{
new Book("1984", "George Orwell"),
new Book("Robinson Crusoe", "Daniel Defoe"),
new Book("Oliver Twist", "Mary Shelly"),
XmlSerializer formatter = new XmlSerializer(typeof(Library));
using (StringWriter sw = new StringWriter())
formatter.Serialize(sw, lib);
Console.Write(sw.ToString());
<my.books genre =""classic"">
<book title = ""1984"" author=""George Orwell"" />
<book title = ""Robinson Crusoe"" author=""Daniel Defoe"" />
<book title = ""Frankenstein"" author=""Mary Shelly"" />
public MyBooks MyBooks { get; set; }
public List<Book> Books { get; set; }
public Library(MyBooks myBooks = null)
public string Genre { get; set; }
public List<Book> Booklist { get; set; }
public MyBooks(string genre, List<Book> booklist = null)
public string Title { get; set; }
public string Author { get; set; }
public Book(string title, string author)