I am trying to learn to serialize XML files and I have hit a snag on accessing a variable that is inside a Class that is inside a List. Here is the declaration code:
public class Library{
public string name;
public List<Book> books;
}
public class Book{
public string name;
}
Here is the code where I populate the List that I'm going to serialize, but whenever I run this code all of the library.books.name
always end up being equal to the last thing I saved book as, in this case "Xenocide".
public void MakeXML(){
Library library = new Library();
library.books = new List<Book>();
library.name = "Red";
Book book = new Book();
book.name = "Hobbit";
library.books.Add(book);
book.name = "Xenocide";
library.books.Add(book);
}
I was wondering if there is a way to acess the variable name inside the Class Book inside the List books, but I can't seem to find something. Any help would be appreciated, Thanks.